Search in sources :

Example 6 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class TileEntityWareHouse method isToolInHut.

/**
     * Check all chests in the worker hut for a required tool.
     * @param tool the type of tool requested (amount is ignored)
     * @param requestingBuilding the building requesting it.
     * @return true if a stack of that type was found
     */
private boolean isToolInHut(final String tool, @NotNull final AbstractBuilding requestingBuilding) {
    @Nullable final AbstractBuilding building = getBuilding();
    boolean hasItem;
    if (building != null) {
        if (tool.equals(Utils.PICKAXE)) {
            hasItem = InventoryUtils.isPickaxeInProvider(building.getTileEntity(), requestingBuilding.getNeededPickaxeLevel(), requestingBuilding.getBuildingLevel());
        } else {
            hasItem = InventoryUtils.isToolInProvider(building.getTileEntity(), tool, requestingBuilding.getBuildingLevel());
        }
        if (hasItem) {
            return true;
        }
        for (final BlockPos pos : building.getAdditionalCountainers()) {
            @Nullable final TileEntity entity = world.getTileEntity(pos);
            if (entity instanceof TileEntityChest) {
                if (tool.equals(Utils.PICKAXE)) {
                    hasItem = InventoryUtils.isPickaxeInProvider(entity, requestingBuilding.getNeededPickaxeLevel(), requestingBuilding.getBuildingLevel());
                } else {
                    hasItem = InventoryUtils.isToolInProvider(entity, tool, requestingBuilding.getBuildingLevel());
                }
                if (hasItem) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 7 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class TileEntityWareHouse method update.

@Override
public void update() {
    super.update();
    if (ticksPassed != WAIT_TICKS) {
        ticksPassed++;
        return;
    }
    ticksPassed = 0;
    final AbstractBuilding wareHouseBuilding = getBuilding();
    if (getColony() != null && wareHouseBuilding instanceof BuildingWareHouse && !((BuildingWareHouse) wareHouseBuilding).getRegisteredDeliverymen().isEmpty()) {
        final Map<BlockPos, AbstractBuilding> buildingMap = getColony().getBuildings();
        if (buildingMap.size() < this.index) {
            this.index = 1;
        }
        int i = 1;
        for (@NotNull final Map.Entry<BlockPos, AbstractBuilding> buildingEntry : buildingMap.entrySet()) {
            if (i == index) {
                if (!taskSet.contains(buildingEntry.getValue()) && buildingEntry.getValue().needsAnything()) {
                    checkInWareHouse(buildingEntry.getValue(), true);
                }
                this.index++;
            }
            i++;
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.BuildingWareHouse)

Example 8 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class BuildRequestMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final BuildRequestMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null) {
        return;
    }
    final AbstractBuilding building = colony.getBuilding(message.buildingId);
    if (building == null) {
        return;
    }
    //Verify player has permission to change this huts settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    if (building.hasWorkOrder()) {
        building.removeWorkOrder();
    } else {
        switch(message.mode) {
            case BUILD:
                building.requestUpgrade();
                break;
            case REPAIR:
                building.requestRepair();
                break;
            default:
                break;
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 9 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class BuildToolPlaceMessage method setupBuilding.

/**
     * setup the building once it has been placed.
     *
     * @param world         World the hut is being placed into.
     * @param player        Who placed the hut.
     * @param sn            The name of the structure.
     * @param workOrderName The name of the work order.
     * @param rotation      The number of times the structure should be rotated.
     * @param buildPos      The location the hut is being placed.
     * @param mirror        Whether or not the strcture is mirrored.
     */
private static void setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!");
    } else {
        if (building.getTileEntity() != null) {
            final Colony colony = ColonyManager.getColony(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        building.setStyle(sn.getStyle());
        building.setRotation(rotation);
        if (mirror) {
            building.setMirror();
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 10 with AbstractBuilding

use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.

the class TransferItemsRequestMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final TransferItemsRequestMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony == null) {
        Log.getLogger().warn("TransferItemsRequestMessage colony is null");
        return;
    }
    final AbstractBuilding building = colony.getBuilding(message.buildingId);
    if (building == null) {
        Log.getLogger().warn("TransferItemsRequestMessage building is null");
        return;
    }
    if (message.quantity <= 0) {
        Log.getLogger().warn("TransferItemsRequestMessage quantity below 0");
        return;
    }
    final Item item = message.itemStack.getItem();
    final int amountToTake = Math.min(message.quantity, InventoryUtils.getItemCountInItemHandler(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage()));
    final ItemStack itemStackToTake = new ItemStack(item, amountToTake, message.itemStack.getItemDamage());
    ItemStack remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(building.getTileEntity(), itemStackToTake);
    if (!InventoryUtils.isItemStackEmpty(remainingItemStack)) {
        //If we still have some to drop, let's try the additional chests now
        if (InventoryUtils.getItemStackSize(remainingItemStack) > 0) {
            final World world = colony.getWorld();
            for (final BlockPos pos : building.getAdditionalCountainers()) {
                final TileEntity entity = world.getTileEntity(pos);
                remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(entity, remainingItemStack);
                if (InventoryUtils.isItemStackEmpty(remainingItemStack)) {
                    break;
                }
            }
        }
    }
    if (InventoryUtils.isItemStackEmpty(remainingItemStack) || InventoryUtils.getItemStackSize(remainingItemStack) != InventoryUtils.getItemStackSize(itemStackToTake)) {
        //Only doing this at the moment as the additional chest do not detect new content
        building.getTileEntity().markDirty();
    }
    int amountToRemoveFromPlayer = amountToTake - InventoryUtils.getItemStackSize(remainingItemStack);
    while (amountToRemoveFromPlayer > 0) {
        final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage());
        final ItemStack itemsTaken = player.inventory.decrStackSize(slot, amountToRemoveFromPlayer);
        amountToRemoveFromPlayer -= InventoryUtils.getItemStackSize(itemsTaken);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)19 BlockPos (net.minecraft.util.math.BlockPos)7 Colony (com.minecolonies.coremod.colony.Colony)5 BuildingGuardTower (com.minecolonies.coremod.colony.buildings.BuildingGuardTower)4 Nullable (org.jetbrains.annotations.Nullable)4 World (net.minecraft.world.World)3 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)2 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 NotNull (org.jetbrains.annotations.NotNull)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingHome (com.minecolonies.coremod.colony.buildings.BuildingHome)1 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.BuildingWareHouse)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1