Jump to content

Hopper only extracting certain item tileentity


Recommended Posts

So my code so far is this
 

public class MixingBowlBlockTileEntity extends LockableLootTileEntity {
 
    private NonNullList<ItemStack> bowlContents = NonNullList.withSize(12, ItemStack.EMPTY);
    PlayerEntity player;
 
    public MixingBowlBlockTileEntity(TileEntityType<?> tileEntityTypeIn) {
        super(tileEntityTypeIn);
    }
    
    
 
    public MixingBowlBlockTileEntity() {
        this(TileEntityTypesInit.MIXING_BOWL.get());
    }
 
    public CompoundNBT write(CompoundNBT compound) {
        super.write(compound);
        if (!this.checkLootAndWrite(compound)) {
            ItemStackHelper.saveAllItems(compound, this.bowlContents);
        }
 
        return compound;
    }
 
    public void read(BlockState state, CompoundNBT nbt) {
        super.read(state, nbt);
        this.bowlContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
        if (!this.checkLootAndRead(nbt)) {
            ItemStackHelper.loadAllItems(nbt, this.bowlContents);
        }
 
    }
 
    public int getSizeInventory() {
        return 12;
    }
 
    protected NonNullList<ItemStack> getItems() {
        return this.bowlContents;
        
    }
    
    
    
 
    protected void setItems(NonNullList<ItemStack> itemsIn) {
        this.bowlContents = itemsIn;
    }
 
 
 
 
 
    protected ITextComponent getDefaultName() {
        return new TranslationTextComponent("container.mixing_bowl");
    }
 
    @Override
    protected Container createMenu(int id, PlayerInventory player) {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public int getInventoryStackLimit() {
        return 1;
    }
 
    public void addItemInventory(PlayerEntity playerIn, Hand handIn) {
        for (int i = 0; i < 9; i++) {
            if (!getStackInSlot(i).getItem().equals(Items.AIR)) {
                continue;
            }
            
            setInventorySlotContents(i, new ItemStack(playerIn.getHeldItemMainhand().getItem()));
            playerIn.getHeldItemMainhand().shrink(1);
            break;
 
        }
        
 
    }
    
    public void addLiquidInventory(PlayerEntity playerIn, Hand handIn) {
        for (int p = 9; p < 12; p++) {
            if (!getStackInSlot(p).getItem().equals(Items.AIR)) {
                continue;
            }
            setInventorySlotContents(p, new ItemStack(playerIn.getHeldItemMainhand().getItem()));
            int slot = playerIn.inventory.currentItem;
            playerIn.replaceItemInInventory(slot, new ItemStack(Items.BUCKET));
            System.out.println(bowlContents);
            break;
        }
    }
    
 
 
 
    public void removeLatestItem(PlayerEntity playerIn, World worldIn, BlockPos posIn, Hand handIn) {
        
        for(int e = 8; e > -1; e--){
            if(!getStackInSlot(e).getItem().equals(Items.AIR)) {
                if(playerIn.inventory.getFirstEmptyStack() != -1) {
                    playerIn.inventory.addItemStackToInventory(getStackInSlot(e).getStack());
                    setInventorySlotContents(e, new ItemStack (Items.AIR));
                    break;
                } else if(playerIn.inventory.hasItemStack(getStackInSlot(e).getStack())) {
                    playerIn.inventory.addItemStackToInventory(getStackInSlot(e).getStack());
                    setInventorySlotContents(e, new ItemStack (Items.AIR));
                    break;
                } else {
                    worldIn.addEntity(new ItemEntity(worldIn, posIn.getX() + 0.5, posIn.getY() + 1.125, posIn.getZ() + 0.5, getStackInSlot(e).getStack()));
                    setInventorySlotContents(e, new ItemStack (Items.AIR));
                    break;
                }
            }
            continue;
            
        }
 
        }
}

And it works fine but hoppers extract an item i dont want it to, I just want the hoopper not to extract a milk_bucket and water_bucket

Any help would be appriciated :)

Link to comment
Share on other sites

private ItemStackHandler getHandler() {
        if (handler == null) {
            handler = new ItemStackHandler(1) {
                @Override
                public ItemStack extractItem(int slot, int amount, boolean simulate) {
                        if (getStackInSlot(1) == new ItemStack (Items.MILK_BUCKET)) {
                            return ItemStack.EMPTY;
                        }
                        
                    return super.extractItem(slot, amount, simulate);
                
            }
            
        };

    }
        return handler;
    }

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.