Search in sources :

Example 1 with TileEntityRack

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) AbstractBlockMinecoloniesRack(com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TileEntityRack

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);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) IWorld(net.minecraft.world.IWorld) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 3 with TileEntityRack

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) IColony(com.minecolonies.api.colony.IColony)

Example 4 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) World(net.minecraft.world.World)

Example 5 with TileEntityRack

use of com.minecolonies.api.tileentities.TileEntityRack in project minecolonies by Minecolonies.

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;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) World(net.minecraft.world.World)

Aggregations

TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)27 TileEntity (net.minecraft.tileentity.TileEntity)27 BlockPos (net.minecraft.util.math.BlockPos)16 AbstractTileEntityRack (com.minecolonies.api.tileentities.AbstractTileEntityRack)12 World (net.minecraft.world.World)12 ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)11 NotNull (org.jetbrains.annotations.NotNull)6 ItemStorage (com.minecolonies.api.crafting.ItemStorage)4 HighlightManager (com.minecolonies.coremod.event.HighlightManager)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 Pane (com.ldtteam.blockout.Pane)2 com.ldtteam.blockout.controls (com.ldtteam.blockout.controls)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 Window (com.ldtteam.blockout.views.Window)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 AbstractBlockMinecoloniesRack (com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack)2 IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)2