use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by ldtteam.
the class InventoryUtils method getCountFromBuilding.
/**
* Count the number of items a building has.
*
* @param provider building to check in.
* @param stack the stack to check.
* @return Amount of occurrences of stacks that match the given stack.
*/
public static int getCountFromBuilding(@NotNull final IBuilding provider, @NotNull final ItemStorage stack) {
int totalCount = 0;
final World world = provider.getColony().getWorld();
for (final BlockPos pos : provider.getContainers()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
totalCount += ((TileEntityRack) entity).getCount(stack);
} else if (entity instanceof ChestTileEntity) {
totalCount += getItemCountInProvider(entity, itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack.getItemStack()));
}
}
}
return totalCount;
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by ldtteam.
the class InventoryUtils method getCountFromBuilding.
/**
* Count the number of items a building has.
*
* @param provider building to check in.
* @param predicate the predicate to match.
* @return Amount of occurrences of stacks that match the given stack.
*/
public static int getCountFromBuilding(@NotNull final IBuilding provider, @NotNull final Predicate<ItemStack> predicate) {
int totalCount = 0;
final World world = provider.getColony().getWorld();
for (final BlockPos pos : provider.getContainers()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
totalCount += ((TileEntityRack) entity).getItemCount(predicate);
} else if (entity instanceof ChestTileEntity) {
totalCount += getItemCountInProvider(entity, predicate);
}
}
}
return totalCount;
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by ldtteam.
the class BlockMinecoloniesRack method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(final BlockItemUseContext context) {
final World worldIn = context.getLevel();
final BlockPos pos = context.getClickedPos();
final BlockState state = defaultBlockState();
final TileEntity entity = worldIn.getBlockEntity(pos);
if (!(entity instanceof TileEntityRack)) {
return super.getStateForPlacement(context);
}
return getPlacementState(state, entity, pos);
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by ldtteam.
the class BlockMinecoloniesRack method onRemove.
@Override
public void onRemove(BlockState state, @NotNull World worldIn, @NotNull BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
TileEntity tileEntity = worldIn.getBlockEntity(pos);
if (tileEntity instanceof TileEntityRack) {
TileEntityRack tileEntityRack = (TileEntityRack) tileEntity;
InventoryUtils.dropItemHandler(tileEntityRack.getInventory(), worldIn, tileEntityRack.getBlockPos().getX(), tileEntityRack.getBlockPos().getY(), tileEntityRack.getBlockPos().getZ());
worldIn.updateNeighbourForOutputSignal(pos, this);
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
}
Aggregations