Switch to new IItemHandler (#3669)

This commit is contained in:
fscan
2018-10-04 20:39:06 +02:00
committed by yueh
parent e21c59b326
commit d88f550eb0
14 changed files with 34 additions and 158 deletions
@@ -3,15 +3,15 @@ package appeng.tile.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import appeng.api.storage.ICellInventory;
import appeng.api.storage.ICellInventoryHandler;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInternalItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
public class AppEngCellInventory implements IInternalItemHandler
public class AppEngCellInventory implements IItemHandlerModifiable
{
private final AppEngInternalInventory inv;
private final ICellInventoryHandler handlerForSlot[];
@@ -78,17 +78,9 @@ public class AppEngCellInventory implements IInternalItemHandler
}
@Override
public boolean isItemValidForSlot( int slot, ItemStack stack )
public boolean isItemValid( int slot, ItemStack stack )
{
return this.inv.isItemValidForSlot( slot, stack );
}
@Override
public void markDirty( int slot )
{
this.persist( slot );
this.inv.markDirty( slot );
this.cleanup( slot );
return this.inv.isItemValid( slot, stack );
}
public void persist()
@@ -25,6 +25,7 @@ import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import appeng.api.AEApi;
@@ -33,14 +34,13 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.core.AELog;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInternalItemHandler;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
import appeng.util.iterators.AEInvIterator;
import appeng.util.iterators.InvIterator;
public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable<ItemStack>
public class AppEngInternalAEInventory implements IItemHandlerModifiable, Iterable<ItemStack>
{
private final IAEAppEngInventory te;
private final IAEItemStack[] inv;
@@ -254,7 +254,7 @@ public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable
private void fireOnChangeInventory( int slot, InvOperation op, ItemStack removed, ItemStack inserted )
{
if( this.te != null && Platform.isServer() )
if( this.te != null && Platform.isServer() && !this.dirtyFlag )
{
this.dirtyFlag = true;
this.te.onChangeInventory( this, slot, op, removed, inserted );
@@ -281,17 +281,8 @@ public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable
}
@Override
public boolean isItemValidForSlot( int slot, ItemStack stack )
public boolean isItemValid( int slot, ItemStack stack )
{
return true;
}
@Override
public void markDirty( int slot )
{
if( !this.dirtyFlag )
{
this.fireOnChangeInventory( slot, InvOperation.DIRTY, ItemStack.EMPTY, ItemStack.EMPTY );
}
}
}
@@ -31,12 +31,11 @@ import net.minecraftforge.items.ItemStackHandler;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.IInternalItemHandler;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public class AppEngInternalInventory extends ItemStackHandler implements IInternalItemHandler, Iterable<ItemStack>
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack>
{
private boolean enableClientEvents = false;
private IAEAppEngInventory te;
@@ -117,7 +116,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements IIntern
@Override
protected void onContentsChanged( int slot )
{
if( this.getTileEntity() != null && this.eventsEnabled() )
if( this.getTileEntity() != null && this.eventsEnabled() && !this.dirtyFlag )
{
this.dirtyFlag = true;
ItemStack newStack = this.getStackInSlot( slot ).copy();
@@ -159,19 +158,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements IIntern
}
@Override
public void markDirty( final int slot )
{
if( this.getTileEntity() != null && this.eventsEnabled() && !this.dirtyFlag )
{
this.dirtyFlag = true;
this.getTileEntity().onChangeInventory( this, slot, InvOperation.DIRTY, ItemStack.EMPTY, ItemStack.EMPTY );
this.getTileEntity().saveChanges();
this.dirtyFlag = false;
}
}
@Override
public boolean isItemValidForSlot( int slot, ItemStack stack )
public boolean isItemValid( int slot, ItemStack stack )
{
if( this.maxStack[slot] == 0 )
{