Switch to new IItemHandler (#3669)
This commit is contained in:
@@ -462,7 +462,6 @@ public abstract class AEBaseContainer extends Container
|
||||
else if( destination.isEmpty() )
|
||||
{
|
||||
cs.putStack( tis.copy() );
|
||||
cs.onSlotChanged();
|
||||
this.updateSlot( cs );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class AppEngSlot extends Slot
|
||||
{
|
||||
if( this.isSlotEnabled() )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( this.itemHandler, this.index, par1ItemStack );
|
||||
return this.itemHandler.isItemValid( this.index, par1ItemStack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -121,7 +121,6 @@ public class AppEngSlot extends Slot
|
||||
if( this.isSlotEnabled() )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.itemHandler, this.index, stack );
|
||||
this.onSlotChanged();
|
||||
|
||||
if( this.getContainer() != null )
|
||||
{
|
||||
@@ -138,7 +137,6 @@ public class AppEngSlot extends Slot
|
||||
@Override
|
||||
public void onSlotChanged()
|
||||
{
|
||||
ItemHandlerUtil.markDirty( this.itemHandler, this.index );
|
||||
this.setIsValid( hasCalculatedValidness.NotAvailable );
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +85,11 @@ public class FluidCellConfig extends CellConfig
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() || stack.getItem() instanceof FluidDummyItem )
|
||||
{
|
||||
super.isItemValidForSlot( slot, stack );
|
||||
super.isItemValid( slot, stack );
|
||||
}
|
||||
FluidStack fluid = FluidUtil.getFluidContained( stack );
|
||||
if( fluid == null || !Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).isPresent() )
|
||||
@@ -100,7 +100,7 @@ public class FluidCellConfig extends CellConfig
|
||||
ItemStack is = Api.INSTANCE.definitions().items().dummyFluidItem().maybeStack( 1 ).get();
|
||||
FluidDummyItem item = (FluidDummyItem) is.getItem();
|
||||
item.setFluidStack( is, fluid );
|
||||
return super.isItemValidForSlot( slot, is );
|
||||
return super.isItemValid( slot, is );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
@@ -24,8 +24,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.inv.IInternalItemHandler;
|
||||
|
||||
|
||||
public class ItemHandlerUtil
|
||||
{
|
||||
@@ -66,37 +64,6 @@ public class ItemHandlerUtil
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void markDirty( final IItemHandler inv, final int slot )
|
||||
{
|
||||
if( inv instanceof IInternalItemHandler )
|
||||
{
|
||||
( (IInternalItemHandler) inv ).markDirty( slot );
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isItemValidForSlot( final IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( inv instanceof IInternalItemHandler )
|
||||
{
|
||||
return ( (IInternalItemHandler) inv ).isItemValidForSlot( slot, stack );
|
||||
}
|
||||
|
||||
// empty slot
|
||||
ItemStack currentStack = inv.getStackInSlot( slot );
|
||||
setStackInSlot( inv, slot, ItemStack.EMPTY );
|
||||
// test insert
|
||||
ItemStack remainder = inv.insertItem( slot, stack, true );
|
||||
// restore slot
|
||||
setStackInSlot( inv, slot, currentStack );
|
||||
|
||||
return remainder.isEmpty() || remainder.getCount() < stack.getCount();
|
||||
}
|
||||
|
||||
public static void copy( final IItemHandler from, final IItemHandler to, boolean deepCopy )
|
||||
{
|
||||
for( int i = 0; i < Math.min( from.getSlots(), to.getSlots() ); ++i )
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
|
||||
public interface IInternalItemHandler extends IItemHandlerModifiable
|
||||
{
|
||||
boolean isItemValidForSlot( int slot, ItemStack stack );
|
||||
|
||||
void markDirty( int slot );
|
||||
}
|
||||
@@ -21,5 +21,5 @@ package appeng.util.inv;
|
||||
|
||||
public enum InvOperation
|
||||
{
|
||||
EXTRACT, INSERT, SET, DIRTY
|
||||
EXTRACT, INSERT, SET
|
||||
}
|
||||
|
||||
@@ -25,12 +25,13 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperChainedItemHandler implements IInternalItemHandler
|
||||
public class WrapperChainedItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private IItemHandler[] itemHandler; // the handlers
|
||||
private int[] baseIndex; // index-offsets of the different handlers
|
||||
@@ -159,20 +160,11 @@ public class WrapperChainedItemHandler implements IInternalItemHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return ItemHandlerUtil.isItemValidForSlot( handler, targetSlot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
ItemHandlerUtil.markDirty( handler, targetSlot );
|
||||
return handler.isItemValid( targetSlot, stack );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,13 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class WrapperFilteredItemHandler implements IInternalItemHandler
|
||||
public class WrapperFilteredItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter filter;
|
||||
@@ -86,18 +87,12 @@ public class WrapperFilteredItemHandler implements IInternalItemHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( !this.filter.allowInsert( this.handler, slot, stack ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ItemHandlerUtil.isItemValidForSlot( this.handler, slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( this.handler, slot );
|
||||
return this.handler.isItemValid( slot, stack );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class WrapperInvItemHandler implements IInventory
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
ItemHandlerUtil.markDirty( this.inv, -1 );
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +129,7 @@ public class WrapperInvItemHandler implements IInventory
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int index, ItemStack stack )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( this.inv, index, stack );
|
||||
return this.inv.isItemValid( index, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,12 +23,13 @@ import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.Lazy;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperLazyItemHandler implements IInternalItemHandler
|
||||
public class WrapperLazyItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final Lazy<IItemHandler> sourceHandler;
|
||||
|
||||
@@ -74,14 +75,8 @@ public class WrapperLazyItemHandler implements IInternalItemHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( this.sourceHandler.get(), slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( this.sourceHandler.get(), slot );
|
||||
return this.sourceHandler.get().isItemValid( slot, stack );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,12 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperRangeItemHandler implements IInternalItemHandler
|
||||
public class WrapperRangeItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler compose;
|
||||
private final int minSlot;
|
||||
@@ -108,22 +109,12 @@ public class WrapperRangeItemHandler implements IInternalItemHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( this.compose, slot + this.minSlot, stack );
|
||||
return this.compose.isItemValid( slot + this.minSlot, stack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( this.compose, slot + this.minSlot );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user