use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class InventoryUtils method hasBuildingEnoughElseCount.
/**
* Check if a building has more than a count in stack. Return the count it has if it has less.
*
* @param provider building to check in.
* @param stack the stack to check.
* @return Amount of occurrences of stacks that match the given predicate.
*/
public static int hasBuildingEnoughElseCount(@NotNull final IBuilding provider, @NotNull final Predicate<ItemStack> stack, final int count) {
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(stack);
}
if (totalCount > count) {
return Integer.MAX_VALUE;
}
}
}
return totalCount;
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class InventoryUtils method countEmptySlotsInBuilding.
/**
* Calculate the number of empty slots in a given building.
* @param ownBuilding the building to check.
* @return the number of empty slots.
*/
public static int countEmptySlotsInBuilding(final IBuilding ownBuilding) {
int totalCount = 0;
final World world = ownBuilding.getColony().getWorld();
for (final BlockPos pos : ownBuilding.getContainers()) {
if (WorldUtil.isBlockLoaded(world, pos)) {
final TileEntity entity = world.getBlockEntity(pos);
if (entity instanceof TileEntityRack) {
totalCount += ((TileEntityRack) entity).getFreeSlots();
}
}
}
return totalCount;
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class BlockMinecoloniesRack method use.
@Override
public ActionResultType use(final BlockState state, final World worldIn, final BlockPos pos, final PlayerEntity player, final Hand hand, final BlockRayTraceResult ray) {
final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(worldIn, pos);
final TileEntity tileEntity = worldIn.getBlockEntity(pos);
if ((colony == null || colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) && tileEntity instanceof TileEntityRack) {
final TileEntityRack rack = (TileEntityRack) tileEntity;
if (!worldIn.isClientSide) {
NetworkHooks.openGui((ServerPlayerEntity) player, rack, buf -> buf.writeBlockPos(rack.getBlockPos()).writeBlockPos(rack.getOtherChest() == null ? BlockPos.ZERO : rack.getOtherChest().getBlockPos()));
}
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}
use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.
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 Minecolonies.
the class BlockMinecoloniesRack method updateShape.
@NotNull
@Override
public BlockState updateShape(@NotNull final BlockState stateIn, final Direction facing, final BlockState state, final IWorld worldIn, final BlockPos currentPos, final BlockPos pos) {
if (state.getBlock() instanceof BlockMinecoloniesRack || stateIn.getBlock() instanceof BlockMinecoloniesRack) {
final TileEntity rack = worldIn.getBlockEntity(pos);
if (rack instanceof TileEntityRack) {
((AbstractTileEntityRack) rack).neighborChanged(currentPos);
}
final TileEntity rack2 = worldIn.getBlockEntity(currentPos);
if (rack2 instanceof TileEntityRack) {
((AbstractTileEntityRack) rack2).neighborChanged(pos);
}
}
return super.updateShape(stateIn, facing, state, worldIn, currentPos, pos);
}
Aggregations