Search in sources :

Example 11 with AbstractBuilding

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

the class MarkBuildingDirtyMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final MarkBuildingDirtyMessage 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;
    }
    building.getTileEntity().markDirty();
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 12 with AbstractBuilding

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

the class EntityAIStructureBuilder method connectBlockToBuildingIfNecessary.

@Override
public void connectBlockToBuildingIfNecessary(@NotNull final Block block, @NotNull final BlockPos pos) {
    final BlockPos buildingLocation = job.getWorkOrder().getBuildingLocation();
    final AbstractBuilding building = this.getOwnBuilding().getColony().getBuilding(buildingLocation);
    if (building != null) {
        building.registerBlockPosition(block, pos);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 13 with AbstractBuilding

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

the class EntityAIStructureBuilder method initiate.

private void initiate() {
    if (!job.hasStructure()) {
        workFrom = null;
        loadStructure();
        final WorkOrderBuildDecoration wo = job.getWorkOrder();
        if (wo == null) {
            Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
            return;
        }
        if (wo instanceof WorkOrderBuild) {
            final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
            if (building == null) {
                Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), wo.getBuildingLocation()));
                return;
            }
            worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, job.getStructure().getName());
            //Don't go through the CLEAR stage for repairs and upgrades
            if (building.getBuildingLevel() > 0) {
                wo.setCleared(true);
            }
        } else {
            worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, wo.getName());
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 14 with AbstractBuilding

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

the class ItemScepterGuard method handleItemUsage.

/**
     * Handles the usage of the item.
     *
     * @param worldIn  the world it is used in.
     * @param pos      the position.
     * @param compound the compound.
     * @param playerIn the player using it.
     * @return if it has been successful.
     */
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
    final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
    if (colony == null) {
        return EnumActionResult.FAIL;
    }
    final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
    final AbstractBuilding hut = colony.getBuilding(guardTower);
    if (hut == null || !(hut instanceof BuildingGuardTower)) {
        return EnumActionResult.FAIL;
    }
    if (BlockPosUtil.getDistance2D(pos, guardTower) > ((BuildingGuardTower) hut).getPatrolDistance()) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
        return EnumActionResult.FAIL;
    }
    final BuildingGuardTower.Task task = BuildingGuardTower.Task.values()[compound.getInteger("task")];
    final CitizenData citizen = ((BuildingGuardTower) hut).getWorker();
    String name = "";
    if (citizen != null) {
        name = " " + citizen.getName();
    }
    if (task.equals(BuildingGuardTower.Task.GUARD)) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
        ((BuildingGuardTower) hut).setGuardTarget(pos);
        playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
    } else {
        if (!compound.hasKey(TAG_LAST_POS)) {
            ((BuildingGuardTower) hut).resetPatrolTargets();
        }
        ((BuildingGuardTower) hut).addPatrolTargets(pos);
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
    }
    BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
    return EnumActionResult.SUCCESS;
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with AbstractBuilding

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

the class EntityAIGoHome method handleSaturation.

/**
     * Handle the saturation of the citizen.
     *
     * @param pos the position.
     */
private void handleSaturation(@NotNull final BlockPos pos) {
    if (citizen.isWorkerAtSiteWithMove(pos, 2) && citizen.getColony() != null && citizen.getCitizenData() != null && citizen.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION) {
        final double currentSaturation = citizen.getCitizenData().getSaturation();
        boolean tookFood = false;
        final AbstractBuilding home = citizen.getColony().getBuilding(pos);
        if (home instanceof BuildingHome && currentSaturation < EntityCitizen.FULL_SATURATION) {
            final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(home.getTileEntity(), itemStack -> itemStack.getItem() instanceof ItemFood);
            if (slot != -1) {
                final ItemStack stack = home.getTileEntity().getStackInSlot(slot);
                if (!InventoryUtils.isItemStackEmpty(stack)) {
                    final int slotToSet = InventoryUtils.getFirstOpenSlotFromItemHandler(new InvWrapper(citizen.getInventoryCitizen()));
                    if (slotToSet == -1) {
                        InventoryUtils.forceItemStackToItemHandler(new InvWrapper(citizen.getInventoryCitizen()), new ItemStack(stack.getItem(), 1), stack1 -> citizen.getWorkBuilding() == null || !citizen.getWorkBuilding().neededForWorker(stack1));
                    } else {
                        citizen.getInventoryCitizen().setInventorySlotContents(slotToSet, new ItemStack(stack.getItem(), 1));
                    }
                    tookFood = true;
                    stack.setCount(stack.getCount() - 1);
                }
                ((BuildingHome) home).setFoodNeeded(false);
            }
        }
        if (!tookFood) {
            requestFoodIfRequired(currentSaturation, home);
        }
    }
}
Also used : ItemFood(net.minecraft.item.ItemFood) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack) 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