Made filter slots be ignored by comparators and stuff

This commit is contained in:
Ellpeck 2016-11-27 11:37:55 +01:00
parent 0b1cb80931
commit 142a07f783
47 changed files with 150 additions and 456 deletions

View file

@ -105,12 +105,6 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud
return new TileEntityAtomicReconstructor(); return new TileEntityAtomicReconstructor();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){

View file

@ -56,10 +56,4 @@ public class BlockBioReactor extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -104,10 +104,4 @@ public class BlockBreaker extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -69,10 +69,4 @@ public class BlockCanolaPress extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -96,12 +96,6 @@ public class BlockCoalGenerator extends BlockContainerBase{
return EnumRarity.RARE; return EnumRarity.RARE;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public IBlockState getStateFromMeta(int meta){ public IBlockState getStateFromMeta(int meta){
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta)); return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta));

View file

@ -81,12 +81,6 @@ public class BlockCoffeeMachine extends BlockContainerBase{
return new TileEntityCoffeeMachine(); return new TileEntityCoffeeMachine();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;

View file

@ -146,12 +146,6 @@ public class BlockCompost extends BlockContainerBase implements IHudDisplay{
return new TileEntityCompost(); return new TileEntityCompost();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.UNCOMMON; return EnumRarity.UNCOMMON;

View file

@ -100,10 +100,4 @@ public class BlockDirectionalBreaker extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -95,12 +95,6 @@ public class BlockDisplayStand extends BlockContainerBase{
return false; return false;
} }
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
this.dropInventory(worldIn, pos);
super.breakBlock(worldIn, pos, state);
}
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;

View file

@ -46,12 +46,6 @@ public class BlockDistributorItem extends BlockContainerBase implements IHudDisp
return new TileEntityDistributorItem(); return new TileEntityDistributorItem();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos()); TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());

View file

@ -99,10 +99,4 @@ public class BlockDropper extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -95,12 +95,6 @@ public class BlockEmpowerer extends BlockContainerBase{
return false; return false;
} }
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
this.dropInventory(worldIn, pos);
super.breakBlock(worldIn, pos, state);
}
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;

View file

@ -70,10 +70,4 @@ public class BlockEnergizer extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -95,10 +95,4 @@ public class BlockFarmer extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -58,10 +58,4 @@ public class BlockFeeder extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.UNCOMMON; return EnumRarity.UNCOMMON;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -51,12 +51,6 @@ public class BlockFermentingBarrel extends BlockContainerBase{
return new TileEntityFermentingBarrel(); return new TileEntityFermentingBarrel();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing par6, float par7, float par8, float par9){
if(!world.isRemote){ if(!world.isRemote){

View file

@ -50,10 +50,4 @@ public class BlockFireworkBox extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -106,10 +106,4 @@ public class BlockFluidCollector extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockDirectional.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -124,12 +124,6 @@ public class BlockFurnaceDouble extends BlockContainerBase{
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
protected ItemBlockBase getItemBlock(){ protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this); return new TheItemBlock(this);

View file

@ -155,15 +155,14 @@ public class BlockGiantChest extends BlockContainerBase{
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state){ public boolean shouldDropInventory(World world, BlockPos pos){
TileEntity tile = world.getTileEntity(pos); TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityGiantChest){ if(tile instanceof TileEntityGiantChest){
if(!ItemUtil.contains(((TileEntityGiantChest)tile).slots, new ItemStack(InitItems.itemCrateKeeper), false)){ if(ItemUtil.contains(((TileEntityGiantChest)tile).slots, new ItemStack(InitItems.itemCrateKeeper), false)){
this.dropInventory(world, pos); return false;
} }
} }
return true;
super.breakBlock(world, pos, state);
} }
@Override @Override

View file

@ -96,10 +96,4 @@ public class BlockGrinder extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -69,18 +69,6 @@ public class BlockInputter extends BlockContainerBase{
return true; return true;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
if(!world.isRemote){
TileEntity aTile = world.getTileEntity(pos);
if(aTile instanceof TileEntityInventoryBase){
TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
this.dropSlotFromInventory(0, tile, world, pos);
}
}
super.breakBlock(world, pos, state);
}
@Override @Override
protected ItemBlockBase getItemBlock(){ protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this); return new TheItemBlock(this);

View file

@ -66,10 +66,4 @@ public class BlockItemRepairer extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -41,10 +41,4 @@ public class BlockLeafGenerator extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -70,12 +70,6 @@ public class BlockMiner extends BlockContainerBase implements IHudDisplay{
return new TileEntityMiner(); return new TileEntityMiner();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){

View file

@ -102,12 +102,6 @@ public class BlockOilGenerator extends BlockContainerBase{
return EnumRarity.RARE; return EnumRarity.RARE;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public IBlockState getStateFromMeta(int meta){ public IBlockState getStateFromMeta(int meta){
return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta)); return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta));

View file

@ -79,13 +79,9 @@ public class BlockPhantom extends BlockContainerBase implements IHudDisplay{
} }
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state){ public boolean shouldDropInventory(World world, BlockPos pos){
if(this.type == Type.PLACER || this.type == Type.BREAKER){ return this.type == Type.PLACER || this.type == Type.BREAKER;
this.dropInventory(world, pos);
} }
super.breakBlock(world, pos, state);
}
@Override @Override
public TileEntity createNewTileEntity(World world, int par2){ public TileEntity createNewTileEntity(World world, int par2){

View file

@ -58,18 +58,4 @@ public class BlockRangedCollector extends BlockContainerBase{
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; return EnumRarity.EPIC;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
if(!world.isRemote){
TileEntity aTile = world.getTileEntity(pos);
if(aTile instanceof TileEntityRangedCollector){
TileEntityRangedCollector tile = (TileEntityRangedCollector)aTile;
for(int i = 0; i < TileEntityRangedCollector.WHITELIST_START; i++){
this.dropSlotFromInventory(i, tile, world, pos);
}
}
}
super.breakBlock(world, pos, state);
}
} }

View file

@ -86,12 +86,6 @@ public class BlockSmileyCloud extends BlockContainerBase{
return new TileEntitySmileyCloud(); return new TileEntitySmileyCloud();
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
@Override @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE; return EnumRarity.RARE;

View file

@ -96,10 +96,4 @@ public class BlockXPSolidifier extends BlockContainerBase{
public IBlockState withMirror(IBlockState state, Mirror mirror){ public IBlockState withMirror(IBlockState state, Mirror mirror){
return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING))); return this.withRotation(state, mirror.toRotation(state.getValue(BlockHorizontal.FACING)));
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
} }

View file

@ -82,7 +82,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
return EnumRarity.COMMON; return EnumRarity.COMMON;
} }
public void dropInventory(World world, BlockPos position){ private void dropInventory(World world, BlockPos position){
if(!world.isRemote){ if(!world.isRemote){
TileEntity aTile = world.getTileEntity(position); TileEntity aTile = world.getTileEntity(position);
if(aTile instanceof TileEntityInventoryBase){ if(aTile instanceof TileEntityInventoryBase){
@ -96,7 +96,7 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
} }
} }
public void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos){ private void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, BlockPos pos){
ItemStack stack = tile.getStackInSlot(i); ItemStack stack = tile.getStackInSlot(i);
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
float dX = world.rand.nextFloat()*0.8F+0.1F; float dX = world.rand.nextFloat()*0.8F+0.1F;
@ -286,4 +286,17 @@ public abstract class BlockContainerBase extends BlockContainer implements ItemB
public EnumBlockRenderType getRenderType(IBlockState state){ public EnumBlockRenderType getRenderType(IBlockState state){
return EnumBlockRenderType.MODEL; return EnumBlockRenderType.MODEL;
} }
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
if(this.shouldDropInventory(world, pos)){
this.dropInventory(world, pos);
}
super.breakBlock(world, pos, state);
}
public boolean shouldDropInventory(World world, BlockPos pos){
return true;
}
} }

View file

@ -32,7 +32,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
public class ContainerBag extends Container implements IButtonReactor{ public class ContainerBag extends Container implements IButtonReactor{
public final FilterSettings filter = new FilterSettings(0, 4, false, true, false, false, 0, -1000); public final FilterSettings filter = new FilterSettings(4, false, true, false, false, 0, -1000);
private final InventoryBag bagInventory; private final InventoryBag bagInventory;
private final InventoryPlayer inventory; private final InventoryPlayer inventory;
private final boolean isVoid; private final boolean isVoid;
@ -45,24 +45,24 @@ public class ContainerBag extends Container implements IButtonReactor{
this.isVoid = isVoid; this.isVoid = isVoid;
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
this.addSlotToContainer(new SlotFilter(this.bagInventory, i, 155, 10+i*18)); this.addSlotToContainer(new SlotFilter(this.filter, i, 155, 10+i*18));
} }
if(this.isVoid){ if(this.isVoid){
this.addSlotToContainer(new SlotDeletion(this.bagInventory, 4, 64, 65){ this.addSlotToContainer(new SlotDeletion(this.bagInventory, 0, 64, 65){
@Override @Override
public boolean isItemValid(ItemStack stack){ public boolean isItemValid(ItemStack stack){
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots); return ContainerBag.this.filter.check(stack);
} }
}); });
} }
else{ else{
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
for(int j = 0; j < 7; j++){ for(int j = 0; j < 7; j++){
this.addSlotToContainer(new Slot(this.bagInventory, j+i*7+4, 10+j*18, 10+i*18){ this.addSlotToContainer(new Slot(this.bagInventory, j+i*7, 10+j*18, 10+i*18){
@Override @Override
public boolean isItemValid(ItemStack stack){ public boolean isItemValid(ItemStack stack){
return ContainerBag.this.filter.check(stack, ContainerBag.this.bagInventory.slots); return ContainerBag.this.filter.check(stack);
} }
}); });
} }
@ -85,7 +85,7 @@ public class ContainerBag extends Container implements IButtonReactor{
ItemStack stack = inventory.getCurrentItem(); ItemStack stack = inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){
ItemDrill.loadSlotsFromNBT(this.bagInventory.slots, inventory.getCurrentItem()); ItemDrill.loadSlotsFromNBT(this.bagInventory, inventory.getCurrentItem());
if(stack.hasTagCompound()){ if(stack.hasTagCompound()){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
this.filter.readFromNBT(compound, "Filter"); this.filter.readFromNBT(compound, "Filter");
@ -95,7 +95,7 @@ public class ContainerBag extends Container implements IButtonReactor{
} }
public static int getSlotAmount(boolean isVoid){ public static int getSlotAmount(boolean isVoid){
return isVoid ? 5 : 32; return isVoid ? 1 : 28;
} }
@Override @Override
@ -141,7 +141,7 @@ public class ContainerBag extends Container implements IButtonReactor{
@Override @Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){ public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = this.bagInventory.slots.size(); int inventoryStart = this.bagInventory.slots.size()+4;
int inventoryEnd = inventoryStart+26; int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1; int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8; int hotbarEnd = hotbarStart+8;
@ -155,7 +155,7 @@ public class ContainerBag extends Container implements IButtonReactor{
//Other Slots in Inventory excluded //Other Slots in Inventory excluded
if(slot >= inventoryStart){ if(slot >= inventoryStart){
//Shift from Inventory //Shift from Inventory
if(this.isVoid || !this.filter.check(newStack, this.bagInventory.slots) || !this.mergeItemStack(newStack, 4, 32, false)){ if(this.isVoid || !this.filter.check(newStack) || !this.mergeItemStack(newStack, 4, 32, false)){
if(slot >= inventoryStart && slot <= inventoryEnd){ if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){ if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return StackUtil.getNull(); return StackUtil.getNull();
@ -207,7 +207,7 @@ public class ContainerBag extends Container implements IButtonReactor{
public void onContainerClosed(EntityPlayer player){ public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem(); ItemStack stack = this.inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemBag){
ItemDrill.writeSlotsToNBT(this.bagInventory.slots, this.inventory.getCurrentItem()); ItemDrill.writeSlotsToNBT(this.bagInventory, this.inventory.getCurrentItem());
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
this.filter.writeToNBT(compound, "Filter"); this.filter.writeToNBT(compound, "Filter");
compound.setBoolean("AutoInsert", this.autoInsert); compound.setBoolean("AutoInsert", this.autoInsert);

View file

@ -61,7 +61,7 @@ public class ContainerDrill extends Container{
ItemStack stack = inventory.getCurrentItem(); ItemStack stack = inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemDrill){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemDrill){
ItemDrill.loadSlotsFromNBT(this.drillInventory.slots, inventory.getCurrentItem()); ItemDrill.loadSlotsFromNBT(this.drillInventory, inventory.getCurrentItem());
} }
} }
@ -132,7 +132,7 @@ public class ContainerDrill extends Container{
public void onContainerClosed(EntityPlayer player){ public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem(); ItemStack stack = this.inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemDrill){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemDrill){
ItemDrill.writeSlotsToNBT(this.drillInventory.slots, this.inventory.getCurrentItem()); ItemDrill.writeSlotsToNBT(this.drillInventory, this.inventory.getCurrentItem());
} }
super.onContainerClosed(player); super.onContainerClosed(player);
} }

View file

@ -59,7 +59,7 @@ public class ContainerFilter extends Container{
ItemStack stack = inventory.getCurrentItem(); ItemStack stack = inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){
ItemDrill.loadSlotsFromNBT(this.filterInventory.slots, inventory.getCurrentItem()); ItemDrill.loadSlotsFromNBT(this.filterInventory, inventory.getCurrentItem());
} }
} }
@ -128,7 +128,7 @@ public class ContainerFilter extends Container{
public void onContainerClosed(EntityPlayer player){ public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem(); ItemStack stack = this.inventory.getCurrentItem();
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){ if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemFilter){
ItemDrill.writeSlotsToNBT(this.filterInventory.slots, this.inventory.getCurrentItem()); ItemDrill.writeSlotsToNBT(this.filterInventory, this.inventory.getCurrentItem());
} }
super.onContainerClosed(player); super.onContainerClosed(player);
} }

View file

@ -39,7 +39,7 @@ public class ContainerInputter extends Container{
for(int i = 0; i < 2; i++){ for(int i = 0; i < 2; i++){
for(int x = 0; x < 3; x++){ for(int x = 0; x < 3; x++){
for(int y = 0; y < 4; y++){ for(int y = 0; y < 4; y++){
this.addSlotToContainer(new SlotFilter(this.tileInputter, 1+y+x*4+i*12, 20+i*84+x*18, 6+y*18)); this.addSlotToContainer(new SlotFilter(i == 0 ? this.tileInputter.leftFilter : this.tileInputter.rightFilter, y+x*4, 20+i*84+x*18, 6+y*18));
} }
} }
} }

View file

@ -32,7 +32,7 @@ public class ContainerLaserRelayItemWhitelist extends Container{
for(int i = 0; i < 2; i++){ for(int i = 0; i < 2; i++){
for(int x = 0; x < 3; x++){ for(int x = 0; x < 3; x++){
for(int y = 0; y < 4; y++){ for(int y = 0; y < 4; y++){
this.addSlotToContainer(new SlotFilter(this.tile.filterInventory, y+x*4+i*12, 20+i*84+x*18, 6+y*18)); this.addSlotToContainer(new SlotFilter(i == 0 ? this.tile.leftFilter : this.tile.rightFilter, y+x*4, 20+i*84+x*18, 6+y*18));
} }
} }
} }

View file

@ -36,7 +36,7 @@ public class ContainerRangedCollector extends Container{
} }
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
for(int j = 0; j < 3; j++){ for(int j = 0; j < 3; j++){
this.addSlotToContainer(new SlotFilter(this.collector, 6+j+i*3, 20+j*18, 6+i*18)); this.addSlotToContainer(new SlotFilter(this.collector.filter, j+i*3, 20+j*18, 6+i*18));
} }
} }
@ -52,7 +52,7 @@ public class ContainerRangedCollector extends Container{
@Override @Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){ public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = 18; int inventoryStart = 6;
int inventoryEnd = inventoryStart+26; int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1; int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8; int hotbarEnd = hotbarStart+8;
@ -66,7 +66,7 @@ public class ContainerRangedCollector extends Container{
//Other Slots in Inventory excluded //Other Slots in Inventory excluded
if(slot >= inventoryStart){ if(slot >= inventoryStart){
//Shift from Inventory //Shift from Inventory
if(!this.mergeItemStack(newStack, 0, TileEntityRangedCollector.WHITELIST_START, false)){ if(!this.mergeItemStack(newStack, 0, 6, false)){
// //
if(slot >= inventoryStart && slot <= inventoryEnd){ if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){ if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){

View file

@ -10,6 +10,7 @@
package de.ellpeck.actuallyadditions.mod.inventory.slot; package de.ellpeck.actuallyadditions.mod.inventory.slot;
import de.ellpeck.actuallyadditions.mod.tile.FilterSettings;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -22,6 +23,10 @@ public class SlotFilter extends Slot{
super(inv, slot, x, y); super(inv, slot, x, y);
} }
public SlotFilter(FilterSettings inv, int slot, int x, int y){
this(inv.filterInventory, slot, x, y);
}
/** /**
* Gets called when the Filter Slot is clicked * Gets called when the Filter Slot is clicked
* Needs to be called in slotClick() in the Container! * Needs to be called in slotClick() in the Container!

View file

@ -19,6 +19,8 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -51,14 +53,14 @@ public class ItemBag extends ItemBase{
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerBag.getSlotAmount(this.isVoid)); IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(this.isVoid));
ItemDrill.loadSlotsFromNBT(slots, stack); ItemDrill.loadSlotsFromNBT(inv, stack);
int slotsTotal = slots.size(); int slotsTotal = inv.getSizeInventory();
int slotsFilled = 0; int slotsFilled = 0;
for(ItemStack slotStack : slots){ for(int i = 0; i < inv.getSizeInventory(); i++){
if(StackUtil.isValid(slotStack)){ if(StackUtil.isValid(inv.getStackInSlot(i))){
slotsFilled++; slotsFilled++;
} }
} }
@ -82,31 +84,31 @@ public class ItemBag extends ItemBase{
boolean changed = false; boolean changed = false;
boolean isVoid = ((ItemBag)invStack.getItem()).isVoid; boolean isVoid = ((ItemBag)invStack.getItem()).isVoid;
NonNullList<ItemStack> inventory = StackUtil.createSlots(ContainerBag.getSlotAmount(isVoid)); IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(isVoid));
ItemDrill.loadSlotsFromNBT(inventory, invStack); ItemDrill.loadSlotsFromNBT(inv, invStack);
FilterSettings filter = new FilterSettings(0, 4, false, false, false, false, 0, 0); FilterSettings filter = new FilterSettings(4, false, false, false, false, 0, 0);
filter.readFromNBT(invStack.getTagCompound(), "Filter"); filter.readFromNBT(invStack.getTagCompound(), "Filter");
if(filter.check(stack, inventory)){ if(filter.check(stack)){
if(isVoid){ if(isVoid){
stack = StackUtil.setStackSize(stack, 0); stack = StackUtil.setStackSize(stack, 0);
changed = true; changed = true;
} }
else{ else{
for(int j = 4; j < inventory.size(); j++){ for(int j = 0; j < inv.getSizeInventory(); j++){
ItemStack bagStack = inventory.get(j); ItemStack bagStack = inv.getStackInSlot(j);
if(StackUtil.isValid(bagStack)){ if(StackUtil.isValid(bagStack)){
if(ItemUtil.canBeStacked(bagStack, stack)){ if(ItemUtil.canBeStacked(bagStack, stack)){
int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack)); int maxTransfer = Math.min(StackUtil.getStackSize(stack), stack.getMaxStackSize()-StackUtil.getStackSize(bagStack));
if(maxTransfer > 0){ if(maxTransfer > 0){
inventory.set(j, StackUtil.addStackSize(bagStack, maxTransfer)); inv.setInventorySlotContents(j, StackUtil.addStackSize(bagStack, maxTransfer));
stack = StackUtil.addStackSize(stack, -maxTransfer); stack = StackUtil.addStackSize(stack, -maxTransfer);
changed = true; changed = true;
} }
} }
} }
else{ else{
inventory.set(j, stack.copy()); inv.setInventorySlotContents(j, stack.copy());
stack = StackUtil.setStackSize(stack, 0); stack = StackUtil.setStackSize(stack, 0);
changed = true; changed = true;
} }
@ -120,7 +122,7 @@ public class ItemBag extends ItemBase{
if(changed){ if(changed){
if(!isVoid){ if(!isVoid){
ItemDrill.writeSlotsToNBT(inventory, invStack); ItemDrill.writeSlotsToNBT(inv, invStack);
} }
event.setResult(Event.Result.ALLOW); event.setResult(Event.Result.ALLOW);
} }
@ -149,16 +151,16 @@ public class ItemBag extends ItemBase{
if(handler != null){ if(handler != null){
boolean changed = false; boolean changed = false;
NonNullList<ItemStack> inventory = StackUtil.createSlots(ContainerBag.getSlotAmount(this.isVoid)); IInventory inv = new InventoryBasic("Bag", false, ContainerBag.getSlotAmount(this.isVoid));
ItemDrill.loadSlotsFromNBT(inventory, stack); ItemDrill.loadSlotsFromNBT(inv, stack);
for(int j = 4; j < inventory.size(); j++){ for(int j = 4; j < inv.getSizeInventory(); j++){
ItemStack invStack = inventory.get(j); ItemStack invStack = inv.getStackInSlot(j);
if(StackUtil.isValid(invStack)){ if(StackUtil.isValid(invStack)){
for(int i = 0; i < handler.getSlots(); i++){ for(int i = 0; i < handler.getSlots(); i++){
ItemStack remain = handler.insertItem(i, invStack, false); ItemStack remain = handler.insertItem(i, invStack, false);
if(!ItemStack.areItemStacksEqual(remain, invStack)){ if(!ItemStack.areItemStacksEqual(remain, invStack)){
inventory.set(j, StackUtil.validateCopy(remain)); inv.setInventorySlotContents(j, StackUtil.validateCopy(remain));
changed = true; changed = true;
if(!StackUtil.isValid(remain)){ if(!StackUtil.isValid(remain)){
@ -170,7 +172,7 @@ public class ItemBag extends ItemBase{
} }
if(changed){ if(changed){
ItemDrill.writeSlotsToNBT(inventory, stack); ItemDrill.writeSlotsToNBT(inv, stack);
} }
} }
} }

View file

@ -34,6 +34,8 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments; import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -46,7 +48,6 @@ import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -76,7 +77,7 @@ public class ItemDrill extends ItemEnergy{
* *
* @param stack The Drill * @param stack The Drill
*/ */
public static void loadSlotsFromNBT(NonNullList<ItemStack> slots, ItemStack stack){ public static void loadSlotsFromNBT(IInventory slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
if(compound != null){ if(compound != null){
TileEntityInventoryBase.loadSlots(slots, compound); TileEntityInventoryBase.loadSlots(slots, compound);
@ -89,7 +90,7 @@ public class ItemDrill extends ItemEnergy{
* @param slots The Slots * @param slots The Slots
* @param stack The Drill * @param stack The Drill
*/ */
public static void writeSlotsToNBT(NonNullList<ItemStack> slots, ItemStack stack){ public static void writeSlotsToNBT(IInventory slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound(); NBTTagCompound compound = stack.getTagCompound();
if(compound == null){ if(compound == null){
compound = new NBTTagCompound(); compound = new NBTTagCompound();
@ -149,17 +150,16 @@ public class ItemDrill extends ItemEnergy{
return StackUtil.getNull(); return StackUtil.getNull();
} }
NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerDrill.SLOT_AMOUNT); InventoryBasic inv = new InventoryBasic("Drill", false, ContainerDrill.SLOT_AMOUNT);
loadSlotsFromNBT(slots, stack); loadSlotsFromNBT(inv, stack);
if(slots != null && slots.size() > 0){ for(int i = 0; i < inv.getSizeInventory(); i++){
for(ItemStack slotStack : slots){ ItemStack slotStack = inv.getStackInSlot(i);
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){ if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){ if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){
return slotStack; return slotStack;
} }
} }
} }
}
return StackUtil.getNull(); return StackUtil.getNull();
} }

View file

@ -16,12 +16,13 @@ import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.List; import java.util.List;
@ -48,14 +49,13 @@ public class ItemFilter extends ItemBase{
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){ public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
NonNullList<ItemStack> slots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT); IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(slots, stack); ItemDrill.loadSlotsFromNBT(inv, stack);
if(slots != null && slots.size() > 0){ for(int i = 0; i < inv.getSizeInventory(); i++){
for(ItemStack slot : slots){ ItemStack slot = inv.getStackInSlot(i);
if(StackUtil.isValid(slot)){ if(StackUtil.isValid(slot)){
tooltip.add(slot.getItem().getItemStackDisplayName(slot)); tooltip.add(slot.getItem().getItemStackDisplayName(slot));
} }
} }
} }
} }
}

View file

@ -14,10 +14,11 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill; import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter; import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -30,9 +31,6 @@ public class FilterSettings{
public final int oredictButtonId; public final int oredictButtonId;
public final int modButtonId; public final int modButtonId;
public final int startSlot;
public final int endSlot;
public boolean isWhitelist; public boolean isWhitelist;
public boolean respectMeta; public boolean respectMeta;
public boolean respectNBT; public boolean respectNBT;
@ -45,9 +43,10 @@ public class FilterSettings{
private boolean lastRespectMod; private boolean lastRespectMod;
private int lastRecpectOredict; private int lastRecpectOredict;
public FilterSettings(int startSlot, int endSlot, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, boolean defaultRespectMod, int defaultRespectOredict, int buttonIdStart){ public final IInventory filterInventory;
this.startSlot = startSlot;
this.endSlot = endSlot; public FilterSettings(int slots, boolean defaultWhitelist, boolean defaultRespectMeta, boolean defaultRespectNBT, boolean defaultRespectMod, int defaultRespectOredict, int buttonIdStart){
this.filterInventory = new InventoryBasic("Filter", false, slots);
this.isWhitelist = defaultWhitelist; this.isWhitelist = defaultWhitelist;
this.respectMeta = defaultRespectMeta; this.respectMeta = defaultRespectMeta;
@ -62,18 +61,20 @@ public class FilterSettings{
this.modButtonId = buttonIdStart+4; this.modButtonId = buttonIdStart+4;
} }
public static boolean check(ItemStack stack, NonNullList<ItemStack> slots, int startSlot, int endSlot, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){ public static boolean check(ItemStack stack, IInventory filter, boolean whitelist, boolean meta, boolean nbt, boolean mod, int oredict){
if(StackUtil.isValid(stack)){ if(StackUtil.isValid(stack)){
for(int i = startSlot; i < endSlot; i++){ for(int i = 0; i < filter.getSizeInventory(); i++){
if(StackUtil.isValid(slots.get(i))){ ItemStack slot = filter.getStackInSlot(i);
if(areEqualEnough(slots.get(i), stack, meta, nbt, mod, oredict)){
if(StackUtil.isValid(slot)){
if(areEqualEnough(slot, stack, meta, nbt, mod, oredict)){
return whitelist; return whitelist;
} }
else if(slots.get(i).getItem() instanceof ItemFilter){ else if(slot.getItem() instanceof ItemFilter){
NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT); IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(filterSlots, slots.get(i)); ItemDrill.loadSlotsFromNBT(inv, slot);
if(filterSlots != null && filterSlots.size() > 0){ for(int k = 0; k < inv.getSizeInventory(); k++){
for(ItemStack filterSlot : filterSlots){ ItemStack filterSlot = inv.getStackInSlot(k);
if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){ if(StackUtil.isValid(filterSlot) && areEqualEnough(filterSlot, stack, meta, nbt, mod, oredict)){
return whitelist; return whitelist;
} }
@ -82,7 +83,6 @@ public class FilterSettings{
} }
} }
} }
}
return !whitelist; return !whitelist;
} }
@ -158,6 +158,7 @@ public class FilterSettings{
compound.setBoolean("NBT", this.respectNBT); compound.setBoolean("NBT", this.respectNBT);
compound.setBoolean("Mod", this.respectMod); compound.setBoolean("Mod", this.respectMod);
compound.setInteger("Oredict", this.respectOredict); compound.setInteger("Oredict", this.respectOredict);
TileEntityInventoryBase.saveSlots(this.filterInventory, compound);
tag.setTag(name, compound); tag.setTag(name, compound);
} }
@ -168,6 +169,7 @@ public class FilterSettings{
this.respectNBT = compound.getBoolean("NBT"); this.respectNBT = compound.getBoolean("NBT");
this.respectMod = compound.getBoolean("Mod"); this.respectMod = compound.getBoolean("Mod");
this.respectOredict = compound.getInteger("Oredict"); this.respectOredict = compound.getInteger("Oredict");
TileEntityInventoryBase.loadSlots(this.filterInventory, compound);
} }
public boolean needsUpdateSend(){ public boolean needsUpdateSend(){
@ -205,7 +207,7 @@ public class FilterSettings{
} }
} }
public boolean check(ItemStack stack, NonNullList<ItemStack> slots){ public boolean check(ItemStack stack){
return check(stack, slots, this.startSlot, this.endSlot, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict); return check(stack, this.filterInventory, this.isWhitelist, this.respectMeta, this.respectNBT, this.respectMod, this.respectOredict);
} }
} }

View file

@ -21,13 +21,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor{ public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor{
public static final int PUT_FILTER_START = 13;
public static final int PULL_FILTER_START = 1;
public static final int OKAY_BUTTON_ID = 133; public static final int OKAY_BUTTON_ID = 133;
public int sideToPut = -1; public int sideToPut = -1;
public int slotToPutStart; public int slotToPutStart;
@ -38,8 +37,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
public int slotToPullEnd; public int slotToPullEnd;
public TileEntity placeToPull; public TileEntity placeToPull;
public boolean isAdvanced; public boolean isAdvanced;
public FilterSettings leftFilter = new FilterSettings(PULL_FILTER_START, PULL_FILTER_START+12, true, true, false, false, 0, -1000); public FilterSettings leftFilter = new FilterSettings(12, true, true, false, false, 0, -1000);
public FilterSettings rightFilter = new FilterSettings(PUT_FILTER_START, PUT_FILTER_START+12, true, true, false, false, 0, -2000); public FilterSettings rightFilter = new FilterSettings(12, true, true, false, false, 0, -2000);
private int lastPutSide; private int lastPutSide;
private int lastPutStart; private int lastPutStart;
private int lastPutEnd; private int lastPutEnd;
@ -127,7 +126,7 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
* @return If the Item is filtered correctly * @return If the Item is filtered correctly
*/ */
private boolean checkBothFilters(ItemStack stack, boolean output){ private boolean checkBothFilters(ItemStack stack, boolean output){
return !this.isAdvanced || (output ? this.rightFilter : this.leftFilter).check(stack, this.slots); return !this.isAdvanced || (output ? this.rightFilter : this.leftFilter).check(stack);
} }
@Override @Override

View file

@ -13,7 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
public class TileEntityInputterAdvanced extends TileEntityInputter{ public class TileEntityInputterAdvanced extends TileEntityInputter{
public TileEntityInputterAdvanced(){ public TileEntityInputterAdvanced(){
super(25, "inputterAdvanced"); super(1, "inputterAdvanced");
this.isAdvanced = true; this.isAdvanced = true;
} }

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -37,10 +38,11 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
} }
} }
public static void saveSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){ public static void saveSlots(IInventory slots, NBTTagCompound compound){
if(slots != null && slots.size() > 0){ if(slots != null && slots.getSizeInventory() > 0){
NBTTagList tagList = new NBTTagList(); NBTTagList tagList = new NBTTagList();
for(ItemStack slot : slots){ for(int i = 0; i < slots.getSizeInventory(); i++){
ItemStack slot = slots.getStackInSlot(i);
NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagCompound tagCompound = new NBTTagCompound();
if(StackUtil.isValid(slot)){ if(StackUtil.isValid(slot)){
slot.writeToNBT(tagCompound); slot.writeToNBT(tagCompound);
@ -51,12 +53,12 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
} }
} }
public static void loadSlots(NonNullList<ItemStack> slots, NBTTagCompound compound){ public static void loadSlots(IInventory slots, NBTTagCompound compound){
if(slots != null && slots.size() > 0){ if(slots != null && slots.getSizeInventory() > 0){
NBTTagList tagList = compound.getTagList("Items", 10); NBTTagList tagList = compound.getTagList("Items", 10);
for(int i = 0; i < slots.size(); i++){ for(int i = 0; i < slots.getSizeInventory(); i++){
NBTTagCompound tagCompound = tagList.getCompoundTagAt(i); NBTTagCompound tagCompound = tagList.getCompoundTagAt(i);
slots.set(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull()); slots.setInventorySlotContents(i, tagCompound != null && tagCompound.hasKey("id") ? new ItemStack(tagCompound) : StackUtil.getNull());
} }
} }
} }
@ -71,7 +73,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){ if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){
saveSlots(this.slots, compound); saveSlots(this, compound);
} }
} }
@ -83,7 +85,7 @@ public abstract class TileEntityInventoryBase extends TileEntityBase implements
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){ if(type == NBTType.SAVE_TILE || (type == NBTType.SYNC && this.shouldSyncSlots())){
loadSlots(this.slots, compound); loadSlots(this, compound);
} }
} }

View file

@ -17,152 +17,18 @@ import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
public final IInventory filterInventory; public FilterSettings leftFilter = new FilterSettings(12, true, true, false, false, 0, -1000);
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000); public FilterSettings rightFilter = new FilterSettings(12, true, true, false, false, 0, -2000);
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000);
private NonNullList<ItemStack> slots = StackUtil.createSlots(24);
public TileEntityLaserRelayItemWhitelist(){ public TileEntityLaserRelayItemWhitelist(){
super("laserRelayItemWhitelist"); super("laserRelayItemWhitelist");
this.filterInventory = new IInventory(){
private TileEntityLaserRelayItemWhitelist tile;
private IInventory setTile(TileEntityLaserRelayItemWhitelist tile){
this.tile = tile;
return this;
}
@Override
public String getName(){
return this.tile.name;
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public void markDirty(){
}
@Override
public boolean isUsableByPlayer(EntityPlayer player){
return this.tile.canPlayerUse(player);
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public int getField(int id){
return 0;
}
@Override
public void setField(int id, int value){
}
@Override
public int getFieldCount(){
return 0;
}
@Override
public void clear(){
this.tile.slots.clear();
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.tile.slots.set(i, stack);
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.tile.slots.size();
}
@Override
public boolean isEmpty(){
return StackUtil.isIInvEmpty(this.tile.slots);
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.tile.slots.get(i);
}
return StackUtil.getNull();
}
@Override
public ItemStack decrStackSize(int i, int j){
if(StackUtil.isValid(this.tile.slots.get(i))){
ItemStack stackAt;
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= j){
stackAt = this.tile.slots.get(i);
this.tile.slots.set(i, StackUtil.getNull());
this.markDirty();
return stackAt;
}
else{
stackAt = this.tile.slots.get(i).splitStack(j);
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= 0){
this.tile.slots.set(i, StackUtil.getNull());
}
this.markDirty();
return stackAt;
}
}
return StackUtil.getNull();
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.tile.slots.get(index);
this.tile.slots.set(index, StackUtil.getNull());
return stack;
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public ITextComponent getDisplayName(){
return new TextComponentTranslation(this.getName());
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return false;
}
}.setTile(this);
} }
@Override @Override
@ -172,15 +38,12 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public boolean isWhitelisted(ItemStack stack, boolean output){ public boolean isWhitelisted(ItemStack stack, boolean output){
return output ? this.rightFilter.check(stack, this.slots) : this.leftFilter.check(stack, this.slots); return output ? this.rightFilter.check(stack) : this.leftFilter.check(stack);
} }
@Override @Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type); super.writeSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE){
TileEntityInventoryBase.saveSlots(this.slots, compound);
}
if(type != NBTType.SAVE_BLOCK){ if(type != NBTType.SAVE_BLOCK){
this.leftFilter.writeToNBT(compound, "LeftFilter"); this.leftFilter.writeToNBT(compound, "LeftFilter");
this.rightFilter.writeToNBT(compound, "RightFilter"); this.rightFilter.writeToNBT(compound, "RightFilter");
@ -190,9 +53,6 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override @Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){ public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type); super.readSyncableNBT(compound, type);
if(type == NBTType.SAVE_TILE){
TileEntityInventoryBase.loadSlots(this.slots, compound);
}
if(type != NBTType.SAVE_BLOCK){ if(type != NBTType.SAVE_BLOCK){
this.leftFilter.readFromNBT(compound, "LeftFilter"); this.leftFilter.readFromNBT(compound, "LeftFilter");
this.rightFilter.readFromNBT(compound, "RightFilter"); this.rightFilter.readFromNBT(compound, "RightFilter");
@ -220,32 +80,31 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
ItemStack copy = stack.copy(); ItemStack copy = stack.copy();
copy = StackUtil.setStackSize(copy, 1); copy = StackUtil.setStackSize(copy, 1);
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){ if(!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){ for(int k = 0; k < usedSettings.filterInventory.getSizeInventory(); k++){
if(StackUtil.isValid(this.slots.get(k))){ ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
if(this.slots.get(k).getItem() instanceof ItemFilter){ if(StackUtil.isValid(slot)){
NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT); if(slot.getItem() instanceof ItemFilter){
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots.get(k)); IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
ItemDrill.loadSlotsFromNBT(inv, slot);
boolean did = false; boolean did = false;
if(filterSlots != null && filterSlots.size() > 0){ for(int j = 0; j < inv.getSizeInventory(); j++){
for(int j = 0; j < filterSlots.size(); j++){ if(!StackUtil.isValid(inv.getStackInSlot(j))){
if(!StackUtil.isValid(filterSlots.get(j))){ inv.setInventorySlotContents(j, copy);
filterSlots.set(j, copy);
did = true; did = true;
break; break;
} }
} }
}
if(did){ if(did){
ItemDrill.writeSlotsToNBT(filterSlots, this.slots.get(k)); ItemDrill.writeSlotsToNBT(inv, slot);
break; break;
} }
} }
} }
else{ else{
this.slots.set(k, copy); usedSettings.filterInventory.setInventorySlotContents(k, copy);
break; break;
} }
} }

View file

@ -26,12 +26,11 @@ import java.util.ArrayList;
public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor{ public class TileEntityRangedCollector extends TileEntityInventoryBase implements IButtonReactor{
public static final int WHITELIST_START = 6;
public static final int RANGE = 6; public static final int RANGE = 6;
public FilterSettings filter = new FilterSettings(WHITELIST_START, WHITELIST_START+12, true, true, false, false, 0, -1000); public FilterSettings filter = new FilterSettings(12, true, true, false, false, 0, -1000);
public TileEntityRangedCollector(){ public TileEntityRangedCollector(){
super(18, "rangedCollector"); super(6, "rangedCollector");
} }
@Override @Override
@ -60,11 +59,11 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
for(EntityItem item : items){ for(EntityItem item : items){
if(!item.isDead && !item.cannotPickup() && StackUtil.isValid(item.getEntityItem())){ if(!item.isDead && !item.cannotPickup() && StackUtil.isValid(item.getEntityItem())){
ItemStack toAdd = item.getEntityItem().copy(); ItemStack toAdd = item.getEntityItem().copy();
if(this.filter.check(toAdd, this.slots)){ if(this.filter.check(toAdd)){
ArrayList<ItemStack> checkList = new ArrayList<ItemStack>(); ArrayList<ItemStack> checkList = new ArrayList<ItemStack>();
checkList.add(toAdd); checkList.add(toAdd);
if(WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, false, true)){ if(WorldUtil.addToInventory(this, checkList, EnumFacing.UP, false, true)){
WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, true, true); WorldUtil.addToInventory(this, checkList, EnumFacing.UP, true, true);
((WorldServer)this.world).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D); ((WorldServer)this.world).spawnParticle(EnumParticleTypes.CLOUD, false, item.posX, item.posY+0.45F, item.posZ, 5, 0, 0, 0, 0.03D);
@ -94,7 +93,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
@Override @Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return slot < WHITELIST_START; return true;
} }
@Override @Override