Switch to new IItemHandler (#3669)
This commit is contained in:
@@ -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