Search in sources :

Example 1 with TileEntityColonyBuilding

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

the class EntityAIWorkDeliveryman method gatherItems.

/**
     * Gather item from chest.
     * Gathers only one stack of the item.
     *
     * @param buildingToDeliver building to deliver to.
     */
private AIState gatherItems(@NotNull final AbstractBuilding buildingToDeliver, @NotNull final BlockPos position) {
    final TileEntity tileEntity = world.getTileEntity(position);
    if (tileEntity instanceof TileEntityChest) {
        if (!(tileEntity instanceof TileEntityColonyBuilding)) {
            if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
                this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 1);
                this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
                this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
                setDelay(DUMP_AND_GATHER_DELAY);
                return GATHER_IN_WAREHOUSE;
            }
            this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 0);
            this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
            this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
        }
        if (buildingToDeliver instanceof BuildingHome) {
            final int extraFood = worker.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION ? 1 : 0;
            //Tries to extract a certain amount of the item of the chest.
            if (InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood, buildingToDeliver.getBuildingLevel() + extraFood, new InvWrapper(worker.getInventoryCitizen()))) {
                worker.setHeldItem(SLOT_HAND);
                setDelay(DUMP_AND_GATHER_DELAY);
                return DELIVERY;
            }
            ((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
            itemsToDeliver.clear();
            return START_WORKING;
        } else if (itemsToDeliver.isEmpty() && !isToolInTileEntity((TileEntityChest) tileEntity, buildingToDeliver.getRequiredTool(), buildingToDeliver.getBuildingLevel())) {
            ((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
            itemsToDeliver.clear();
            return START_WORKING;
        } else if (!itemsToDeliver.isEmpty()) {
            final ItemStack stack = itemsToDeliver.get(0);
            if (isInTileEntity((TileEntityChest) tileEntity, stack)) {
                itemsToDeliver.remove(0);
                worker.setHeldItem(SLOT_HAND);
                setDelay(DUMP_AND_GATHER_DELAY);
                return DELIVERY;
            }
            ((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
            itemsToDeliver.clear();
            return START_WORKING;
        }
    }
    setDelay(DUMP_AND_GATHER_DELAY);
    return GATHER_IN_WAREHOUSE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemFood(net.minecraft.item.ItemFood) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileEntityColonyBuilding

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

the class BlockHutTownHall method onBlockPlacedBy.

@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
    if (worldIn.isRemote) {
        return;
    }
    if (placer.getActiveHand().equals(EnumHand.MAIN_HAND)) {
        final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
        String style = Constants.DEFAULT_STYLE;
        final TileEntity tileEntity = worldIn.getTileEntity(pos);
        if (tileEntity instanceof TileEntityColonyBuilding && !((TileEntityColonyBuilding) tileEntity).getStyle().isEmpty()) {
            style = ((TileEntityColonyBuilding) tileEntity).getStyle();
        }
        if (colony == null || !ColonyManager.isTooCloseToColony(worldIn, pos)) {
            ColonyManager.createColony(worldIn, pos, (EntityPlayer) placer, style);
        } else {
            colony.setStyle(style);
        }
    }
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Colony(com.minecolonies.coremod.colony.Colony)

Example 3 with TileEntityColonyBuilding

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

the class AbstractBlockHut method onBlockPlacedBy.

/**
 * Event-Handler for placement of this block.
 * <p>
 * Override for custom logic.
 *
 * @param worldIn the word we are in.
 * @param pos     the position where the block was placed.
 * @param state   the state the placed block is in.
 * @param placer  the player placing the block.
 * @param stack   the itemstack from where the block was placed.
 * @see Block#onBlockPlacedBy(World, BlockPos, IBlockState,
 * EntityLivingBase, ItemStack)
 */
@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
    super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
    /*
        Only work on server side
        */
    if (worldIn.isRemote) {
        return;
    }
    final TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (placer instanceof EntityPlayer && tileEntity instanceof TileEntityColonyBuilding) {
        @NotNull final TileEntityColonyBuilding hut = (TileEntityColonyBuilding) tileEntity;
        @Nullable final Colony colony = ColonyManager.getColony(worldIn, hut.getPosition());
        if (colony != null) {
            colony.getBuildingManager().addNewBuilding(hut, worldIn);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with TileEntityColonyBuilding

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

the class GuiHandler method getServerGuiElement.

@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    if (id == ID.DEFAULT.ordinal()) {
        final BlockPos pos = new BlockPos(x, y, z);
        final TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof ScarecrowTileEntity) {
            return new ContainerField((ScarecrowTileEntity) tileEntity, player.inventory, world, pos);
        } else if (tileEntity instanceof TileEntityRack) {
            return new ContainerRack((TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), player.inventory);
        } else {
            @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, new BlockPos(x, y, z));
            if (building != null) {
                return new CraftingGUIBuilding(player.inventory, world);
            }
            return null;
        }
    } else if (id == ID.BUILDING_INVENTORY.ordinal()) {
        final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
        if (entity instanceof TileEntityColonyBuilding) {
            final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
            final Colony colony = ColonyManager.getClosestColony(world, tileEntityColonyBuilding.getPos());
            return new ContainerMinecoloniesBuildingInventory(player.inventory, tileEntityColonyBuilding, colony.getID(), tileEntityColonyBuilding.getPos());
        }
    } else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
        final Colony colony = ColonyManager.getColony(x);
        final CitizenData citizen = colony.getCitizenManager().getCitizen(y);
        final AbstractBuilding building = citizen.getWorkBuilding();
        return new ContainerMinecoloniesCitizenInventory(player.inventory, citizen.getInventory(), colony.getID(), building == null ? null : building.getID(), citizen.getId());
    }
    return null;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) BlockPos(net.minecraft.util.math.BlockPos) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 5 with TileEntityColonyBuilding

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

the class GuiHandler method getClientGuiElement.

@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
    if (id == ID.DEFAULT.ordinal()) {
        final BlockPos pos = new BlockPos(x, y, z);
        final TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof ScarecrowTileEntity) {
            return new GuiField(player.inventory, (ScarecrowTileEntity) tileEntity, world, pos);
        } else if (tileEntity instanceof TileEntityRack) {
            return new GuiRack(player.inventory, (TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), world, pos);
        } else {
            @Nullable final AbstractBuildingView building = ColonyManager.getBuildingView(new BlockPos(x, y, z));
            if (building instanceof AbstractBuildingWorker.View) {
                return new WindowGuiCrafting(player.inventory, world, (AbstractBuildingWorker.View) building);
            }
        }
    } else if (id == ID.BUILDING_INVENTORY.ordinal()) {
        final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
        if (entity instanceof TileEntityColonyBuilding) {
            final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
            return new GuiChest(player.inventory, tileEntityColonyBuilding);
        }
    } else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
        final ColonyView view = ColonyManager.getColonyView(x);
        final CitizenDataView citizenDataView = view.getCitizen(y);
        return new GuiChest(player.inventory, citizenDataView.getInventory());
    }
    return null;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntity(net.minecraft.tileentity.TileEntity) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) AbstractBuildingView(com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView) TileEntityRack(com.minecolonies.coremod.tileentities.TileEntityRack) AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) WindowGuiCrafting(com.minecolonies.coremod.client.gui.WindowGuiCrafting) BlockPos(net.minecraft.util.math.BlockPos) GuiChest(net.minecraft.client.gui.inventory.GuiChest)

Aggregations

TileEntityColonyBuilding (com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)13 TileEntity (net.minecraft.tileentity.TileEntity)10 ItemStack (net.minecraft.item.ItemStack)4 Colony (com.minecolonies.coremod.colony.Colony)3 TileEntityChest (net.minecraft.tileentity.TileEntityChest)3 BlockPos (net.minecraft.util.math.BlockPos)3 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)3 NotNull (org.jetbrains.annotations.NotNull)3 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)2 ScarecrowTileEntity (com.minecolonies.coremod.tileentities.ScarecrowTileEntity)2 TileEntityRack (com.minecolonies.coremod.tileentities.TileEntityRack)2 ItemFood (net.minecraft.item.ItemFood)2 Nullable (org.jetbrains.annotations.Nullable)2 ImmutableList (com.google.common.collect.ImmutableList)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 Configurations (com.minecolonies.api.configuration.Configurations)1 ItemStorage (com.minecolonies.api.crafting.ItemStorage)1