From 301ec86c27d09dac946313b7bdffb7c10d3a9bcd Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Wed, 22 Apr 2020 17:14:21 +0100 Subject: [PATCH] Add comparator behaviour to bookshelves --- .../wizardry/block/BlockBookshelf.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/electroblob/wizardry/block/BlockBookshelf.java b/src/main/java/electroblob/wizardry/block/BlockBookshelf.java index b84ed7d8..267cc4b1 100644 --- a/src/main/java/electroblob/wizardry/block/BlockBookshelf.java +++ b/src/main/java/electroblob/wizardry/block/BlockBookshelf.java @@ -29,7 +29,6 @@ import net.minecraft.world.IWorldEventListener; import net.minecraft.world.World; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.Properties; -import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -145,6 +144,31 @@ public class BlockBookshelf extends BlockHorizontal implements ITileEntityProvid return true; } + @Override + public boolean hasComparatorInputOverride(IBlockState state){ + return true; + } + + @Override + public int getComparatorInputOverride(IBlockState state, World world, BlockPos pos){ + + TileEntity tileEntity = world.getTileEntity(pos); + + if(tileEntity instanceof TileEntityBookshelf){ + + int slotsOccupied = 0; + + for(int i = 0; i < ((TileEntityBookshelf)tileEntity).getSizeInventory(); i++){ + if(!((TileEntityBookshelf)tileEntity).getStackInSlot(i).isEmpty()) slotsOccupied++; + } + + return slotsOccupied; + + } + + return super.getComparatorInputOverride(state, world, pos); + } + @Override public boolean eventReceived(IBlockState state, World world, BlockPos pos, int id, int param){ super.eventReceived(state, world, pos, id, param);