Search in sources :

Example 11 with TileEntityColonyBuilding

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

the class AbstractEntityAIGuard method goToBuilding.

/**
 * Goes back to the building and tries to take armour from it when he hasn't in his inventory.
 *
 * @return the next state to go to.
 */
protected AIState goToBuilding() {
    if (walkToBuilding()) {
        return GUARD_RESTOCK;
    }
    final AbstractBuildingWorker workBuilding = getOwnBuilding();
    if (workBuilding != null) {
        final TileEntityColonyBuilding chest = workBuilding.getTileEntity();
        for (int i = 0; i < workBuilding.getTileEntity().getSizeInventory(); i++) {
            final ItemStack stack = chest.getStackInSlot(i);
            if (ItemStackUtils.isEmpty(stack)) {
                continue;
            }
            if (stack.getItem() instanceof ItemArmor && worker.getItemStackFromSlot(((ItemArmor) stack.getItem()).armorType) == null) {
                final int emptySlot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(worker.getInventoryCitizen()), ItemStackUtils::isEmpty);
                if (emptySlot != -1) {
                    new InvWrapper(worker.getInventoryCitizen()).insertItem(emptySlot, stack, false);
                    chest.setInventorySlotContents(i, ItemStackUtils.EMPTY);
                }
            }
            dumpAfterActions = DUMP_BASE * workBuilding.getBuildingLevel();
        }
    }
    attacksExecuted = 0;
    return GUARD_SEARCH_TARGET;
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) ItemArmor(net.minecraft.item.ItemArmor) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 12 with TileEntityColonyBuilding

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

the class AbstractBlockHut method onBlockPlacedByBuildTool.

/**
 * 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.
 * @param mirror  the mirror used.
 * @param style   the style of the building
 * @see Block#onBlockPlacedBy(World, BlockPos, IBlockState,
 * EntityLivingBase, ItemStack)
 */
public void onBlockPlacedByBuildTool(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack, final boolean mirror, final String style) {
    final TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity instanceof TileEntityColonyBuilding) {
        ((TileEntityColonyBuilding) tileEntity).setMirror(mirror);
        ((TileEntityColonyBuilding) tileEntity).setStyle(style);
    }
    onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding)

Example 13 with TileEntityColonyBuilding

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

the class InventoryTest method setupInventories.

@Before
public void setupInventories() {
    final TileEntityColonyBuilding buildingTileEntity = new TileEntityColonyBuilding();
    buildingTileEntity.setBuilding(building);
    this.inventory = buildingTileEntity;
}
Also used : TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Before(org.junit.Before)

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