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());
}
}
}
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();
}
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();
}
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;
}
}
}
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");
}
}
}
Aggregations