Search in sources :

Example 1 with AbstractTileEntityRack

use of com.minecolonies.api.tileentities.AbstractTileEntityRack in project minecolonies by ldtteam.

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 AbstractTileEntityRack

use of com.minecolonies.api.tileentities.AbstractTileEntityRack in project minecolonies by ldtteam.

the class BlockMinecoloniesRack method spawnAfterBreak.

@Override
public void spawnAfterBreak(final BlockState state, final ServerWorld worldIn, final BlockPos pos, final ItemStack stack) {
    final TileEntity tileentity = worldIn.getBlockEntity(pos);
    if (tileentity instanceof TileEntityRack) {
        final IItemHandler handler = ((AbstractTileEntityRack) tileentity).getInventory();
        InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
    }
    super.spawnAfterBreak(state, worldIn, pos, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack)

Example 3 with AbstractTileEntityRack

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

the class TileEntityWareHouse method searchMostEmptyRack.

/**
 * Search for the chest with the least items in it.
 *
 * @return the tileEntity of this chest.
 */
@Nullable
private TileEntity searchMostEmptyRack() {
    int freeSlots = 0;
    TileEntity emptiestChest = null;
    for (@NotNull final BlockPos pos : getBuilding().getContainers()) {
        final TileEntity entity = getLevel().getBlockEntity(pos);
        if (entity instanceof TileEntityRack) {
            if (((AbstractTileEntityRack) entity).isEmpty()) {
                return entity;
            }
            final int tempFreeSlots = ((AbstractTileEntityRack) entity).getFreeSlots();
            if (tempFreeSlots > freeSlots) {
                freeSlots = tempFreeSlots;
                emptiestChest = entity;
            }
        }
    }
    return emptiestChest;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AbstractTileEntityRack

use of com.minecolonies.api.tileentities.AbstractTileEntityRack 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 5 with AbstractTileEntityRack

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

the class BlockMinecoloniesRack method spawnAfterBreak.

@Override
public void spawnAfterBreak(final BlockState state, final ServerWorld worldIn, final BlockPos pos, final ItemStack stack) {
    final TileEntity tileentity = worldIn.getBlockEntity(pos);
    if (tileentity instanceof TileEntityRack) {
        final IItemHandler handler = ((AbstractTileEntityRack) tileentity).getInventory();
        InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
    }
    super.spawnAfterBreak(state, worldIn, pos, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.api.tileentities.TileEntityRack) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler) AbstractTileEntityRack(com.minecolonies.api.tileentities.AbstractTileEntityRack)

Aggregations

AbstractTileEntityRack (com.minecolonies.api.tileentities.AbstractTileEntityRack)6 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)6 TileEntity (net.minecraft.tileentity.TileEntity)6 NotNull (org.jetbrains.annotations.NotNull)4 AbstractBlockMinecoloniesRack (com.minecolonies.api.blocks.AbstractBlockMinecoloniesRack)2 ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 Nullable (org.jetbrains.annotations.Nullable)2