Search in sources :

Example 1 with WorkOrderBuild

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuild in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method initiate.

private void initiate() {
    if (!job.hasStructure()) {
        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().getBuildingManager().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 2 with WorkOrderBuild

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuild in project minecolonies by Minecolonies.

the class EntityAIStructureBuilder method loadStructure.

/**
 * Load the struction into the AI.
 */
private void loadStructure() {
    WorkOrderBuildDecoration workOrder = null;
    workOrder = job.getWorkOrder();
    if (workOrder == null) {
        return;
    }
    final BlockPos pos = workOrder.getBuildingLocation();
    if (workOrder instanceof WorkOrderBuild && worker.getColony().getBuildingManager().getBuilding(pos) == null) {
        Log.getLogger().warn("AbstractBuilding does not exist - removing build request");
        worker.getColony().getWorkManager().removeWorkOrder(workOrder);
        return;
    }
    final int tempRotation = workOrder.getRotation(world);
    loadStructure(workOrder.getStructureName(), tempRotation, pos, workOrder.isMirrored());
    workOrder.setCleared(false);
    workOrder.setRequested(false);
    // We need to deal with materials
    requestMaterialsIfRequired();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) BlockPos(net.minecraft.util.math.BlockPos) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 3 with WorkOrderBuild

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuild in project minecolonies by Minecolonies.

the class AbstractBuilding method requestWorkOrder.

/**
 * Adds work orders to the {@link Colony#workManager}.
 *
 * @param level Desired level.
 */
protected void requestWorkOrder(final int level) {
    for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
        if (o.getBuildingLocation().equals(getID())) {
            return;
        }
    }
    colony.getWorkManager().addWorkOrder(new WorkOrderBuild(this, level), false);
    LanguageHandler.sendPlayersMessage(colony.getMessageEntityPlayers(), "com.minecolonies.coremod.workOrderAdded");
    markDirty();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with WorkOrderBuild

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuild in project minecolonies by Minecolonies.

the class AbstractBuilding method removeWorkOrder.

/**
 * Remove the work order for the building.
 * <p>
 * Remove either the upgrade or repair work order
 */
public void removeWorkOrder() {
    for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
        if (o.getBuildingLocation().equals(getID())) {
            colony.getWorkManager().removeWorkOrder(o.getID());
            markDirty();
            final int citizenThatIsBuilding = o.getClaimedBy();
            final CitizenData data = colony.getCitizenManager().getCitizen(citizenThatIsBuilding);
            if (data != null && data.getWorkBuilding() != null) {
                data.getWorkBuilding().cancelAllRequestsOfCitizen(data);
            }
            return;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with WorkOrderBuild

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuild in project minecolonies by Minecolonies.

the class BuildToolPasteMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final BuildToolPasteMessage message, final EntityPlayerMP player) {
    final StructureName sn = new StructureName(message.structureName);
    if (!Structures.hasMD5(sn)) {
        player.sendMessage(new TextComponentString("Can not build " + message.workOrderName + ": schematic missing!"));
        return;
    }
    if (player.capabilities.isCreativeMode) {
        if (message.isHut) {
            handleHut(CompatibilityUtils.getWorld(player), player, sn, message.rotation, message.pos, message.mirror);
        }
        StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
        if (message.isHut) {
            @Nullable final AbstractBuilding building = ColonyManager.getBuilding(CompatibilityUtils.getWorld(player), message.pos);
            if (building != null) {
                final WorkOrderBuild workOrder = new WorkOrderBuild(building, 1);
                ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorld(player));
            }
        }
    } else if (message.freeMode != null) {
        if (player.getStatFile().readStat(StatList.getObjectUseStats(ModItems.supplyChest)) > 0) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.error.supplyChestAlreadyPlaced");
            return;
        }
        final List<ItemStack> stacks = new ArrayList<>();
        final int chestHeight;
        if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYSHIP) {
            stacks.add(new ItemStack(ModItems.supplyChest));
            chestHeight = SUPPLY_SHIP_CHEST_HEIGHT;
        } else if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYCAMP) {
            stacks.add(new ItemStack(ModItems.supplyCamp));
            chestHeight = 1;
        } else {
            chestHeight = 0;
        }
        player.addStat(StatList.getObjectUseStats(ModItems.supplyChest));
        if (InventoryUtils.removeStacksFromItemHandler(new InvWrapper(player.inventory), stacks)) {
            StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
            player.getServerWorld().setBlockState(message.pos.up(chestHeight), Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, player.getHorizontalFacing()));
            fillChest((TileEntityChest) player.getServerWorld().getTileEntity(message.pos.up(chestHeight)));
        } else {
            LanguageHandler.sendPlayerMessage(player, "item.supplyChestDeployer.missing");
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.minecolonies.coremod.colony.StructureName) ArrayList(java.util.ArrayList) StatList(net.minecraft.stats.StatList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) TextComponentString(net.minecraft.util.text.TextComponentString) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)10 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)5 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)3 BlockPos (net.minecraft.util.math.BlockPos)3 NotNull (org.jetbrains.annotations.NotNull)3 StructureWrapper (com.minecolonies.coremod.util.StructureWrapper)2 Tuple (net.minecraft.util.Tuple)2 Nullable (org.jetbrains.annotations.Nullable)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 BuildingBuilder (com.minecolonies.coremod.colony.buildings.BuildingBuilder)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 JobBuilder (com.minecolonies.coremod.colony.jobs.JobBuilder)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ItemStack (net.minecraft.item.ItemStack)1 StatList (net.minecraft.stats.StatList)1 TileEntityChest (net.minecraft.tileentity.TileEntityChest)1 EnumFacing (net.minecraft.util.EnumFacing)1