Add comparator behaviour to bookshelves

This commit is contained in:
Electroblob77
2020-04-22 17:14:21 +01:00
parent ee96ff3ddd
commit 301ec86c27
@@ -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);