Search in sources :

Example 1 with TileEntityRack

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

the class BlockMinecoloniesRack method breakBlock.

@Override
public void breakBlock(final World worldIn, final BlockPos pos, final IBlockState state) {
    final TileEntity tileentity = worldIn.getTileEntity(pos);
    if (tileentity instanceof TileEntityRack) {
        final IItemHandler handler = ((TileEntityRack) tileentity).getInventory();
        InventoryUtils.dropItemHandler(handler, worldIn, pos.getX(), pos.getY(), pos.getZ());
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) IItemHandler(net.minecraftforge.items.IItemHandler)

Example 2 with TileEntityRack

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

the class BlockMinecoloniesRack method neighborChanged.

@Override
public void neighborChanged(final IBlockState state, final World worldIn, final BlockPos pos, final Block blockIn, final BlockPos fromPos) {
    if (state.getBlock() instanceof BlockMinecoloniesRack) {
        final TileEntity rack = worldIn.getTileEntity(pos);
        for (final EnumFacing offsetFacing : BlockHorizontal.FACING.getAllowedValues()) {
            final BlockPos neighbor = pos.offset(offsetFacing);
            final Block block = worldIn.getBlockState(neighbor).getBlock();
            if (rack instanceof TileEntityRack && pos.getY() == neighbor.getY() && !pos.equals(neighbor) && !pos.equals(BlockPos.ORIGIN) && (block instanceof BlockMinecoloniesRack || blockIn instanceof BlockMinecoloniesRack)) {
                ((TileEntityRack) rack).neighborChanged(neighbor);
            }
        }
    }
    super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with TileEntityRack

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

the class BlockMinecoloniesRack method onBlockActivated.

@Override
public boolean onBlockActivated(final World worldIn, final BlockPos pos, final IBlockState state, final EntityPlayer playerIn, final EnumHand hand, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
    final Colony colony = ColonyManager.getColony(worldIn, pos);
    final TileEntity tileEntity = worldIn.getTileEntity(pos);
    if ((colony == null || colony.getPermissions().hasPermission(playerIn, Action.ACCESS_HUTS)) && tileEntity instanceof TileEntityRack) {
        if (!worldIn.isRemote) {
            playerIn.openGui(MineColonies.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) Colony(com.minecolonies.coremod.colony.Colony)

Example 4 with TileEntityRack

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

the class BlockMinecoloniesRack method getActualState.

/**
 * @deprecated but we still need this because there is nothing better.
 */
@Override
public IBlockState getActualState(final IBlockState state, final IBlockAccess worldIn, final BlockPos pos) {
    final TileEntity entity = worldIn.getTileEntity(pos);
    if (!(entity instanceof TileEntityRack)) {
        return super.getActualState(state, worldIn, pos);
    }
    final TileEntityRack rack = (TileEntityRack) entity;
    if (rack.isEmpty() && (rack.getOtherChest() == null || rack.getOtherChest().isEmpty())) {
        if (rack.getOtherChest() != null) {
            if (rack.isMain()) {
                return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULTDOUBLE).withProperty(FACING, BlockPosUtil.getFacing(rack.getNeighbor(), pos));
            } else {
                return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
            }
        } else {
            return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.DEFAULT);
        }
    } else {
        if (rack.getOtherChest() != null) {
            if (rack.isMain()) {
                return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULLDOUBLE).withProperty(FACING, BlockPosUtil.getFacing(rack.getNeighbor(), pos));
            } else {
                return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.EMPTYAIR);
            }
        } else {
            return state.withProperty(BlockMinecoloniesRack.VARIANT, RackType.FULL);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack)

Example 5 with TileEntityRack

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

the class BuildingWareHouse method handleBuildingOverChest.

/**
 * Handles the chest placement.
 *
 * @param pos   at pos.
 * @param chest the entity.
 * @param world the world.
 */
public static void handleBuildingOverChest(@NotNull final BlockPos pos, final TileEntityChest chest, final World world) {
    final List<ItemStack> inventory = new ArrayList<>();
    final int size = chest.getSingleChestHandler().getSlots();
    for (int slot = 0; slot < size; slot++) {
        final ItemStack stack = chest.getSingleChestHandler().getStackInSlot(slot);
        if (!ItemStackUtils.isEmpty(stack)) {
            inventory.add(stack.copy());
        }
        chest.getSingleChestHandler().extractItem(slot, Integer.MAX_VALUE, false);
    }
    world.setBlockState(pos, ModBlocks.blockRack.getDefaultState(), 0x03);
    final TileEntity entity = world.getTileEntity(pos);
    if (entity instanceof TileEntityRack) {
        for (final ItemStack stack : inventory) {
            if (!ItemStackUtils.isEmpty(stack)) {
                InventoryUtils.addItemStackToItemHandler(((TileEntityRack) entity).getInventory(), stack);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileEntityRack (com.minecolonies.coremod.tileentities.TileEntityRack)8 TileEntity (net.minecraft.tileentity.TileEntity)7 TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)3 BlockPos (net.minecraft.util.math.BlockPos)3 AbstractBuildingView (com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView)2 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 TypeToken (com.google.common.reflect.TypeToken)1 StandardFactoryController (com.minecolonies.api.colony.requestsystem.StandardFactoryController)1 IRequestSystemBuildingDataStore (com.minecolonies.api.colony.requestsystem.data.IRequestSystemBuildingDataStore)1 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)1 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)1 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)1 IRequestResolver (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)1 IRequestResolverProvider (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolverProvider)1