use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding 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
*/
@Override
public void removeWorkOrder() {
for (@NotNull final WorkOrderBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuilding.class)) {
if (o.getLocation().equals(getID())) {
colony.getWorkManager().removeWorkOrder(o.getID());
markDirty();
final BlockPos buildingPos = o.getClaimedBy();
final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
if (building != null) {
for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
for (final ICitizenData citizen : module.getAssignedCitizen()) {
building.cancelAllRequestsOfCitizen(citizen);
}
}
}
return;
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method checkForWorkOrder.
/**
* Checks if we got a valid workorder.
*
* @return true if we got a workorder to work with
*/
private boolean checkForWorkOrder() {
if (!job.hasWorkOrder()) {
building.searchWorkOrder();
building.setProgressPos(null, BuildingStructureHandler.Stage.CLEAR);
return false;
}
final IWorkOrder wo = job.getWorkOrder();
if (wo == null) {
job.setWorkOrder(null);
building.setProgressPos(null, null);
return false;
}
final IBuilding building = job.getColony().getBuildingManager().getBuilding(wo.getLocation());
if (building == null && wo instanceof WorkOrderBuilding && wo.getWorkOrderType() != WorkOrderType.REMOVE) {
job.complete();
return false;
}
return true;
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.
the class AbstractBuilding method requestWorkOrder.
/**
* Adds work orders to the {@link Colony#getWorkManager()}.
*
* @param type what to do with the work order
* @param builder the assigned builder.
*/
protected void requestWorkOrder(WorkOrderType type, final BlockPos builder) {
for (@NotNull final WorkOrderBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuilding.class)) {
if (o.getLocation().equals(getID())) {
return;
}
}
WorkOrderBuilding workOrder = WorkOrderBuilding.create(type, this);
if (type == WorkOrderType.REMOVE && !canDeconstruct()) {
MessageUtils.format(BUILDER_CANNOT_DECONSTRUCT).sendTo(colony).forAllPlayers();
return;
}
if (type == WorkOrderType.REMOVE && !canBeBuiltByBuilder(workOrder.getTargetLevel()) && !workOrder.canBeResolved(colony, workOrder.getTargetLevel())) {
MessageUtils.format(BUILDER_NECESSARY, Integer.toString(workOrder.getTargetLevel())).sendTo(colony).forAllPlayers();
return;
}
if (workOrder.tooFarFromAnyBuilder(colony, workOrder.getTargetLevel()) && builder.equals(BlockPos.ZERO)) {
MessageUtils.format(BUILDER_TOO_FAR_AWAY).sendTo(colony).forAllPlayers();
return;
}
if (getCorners().getA().getY() >= MAX_BUILD_HEIGHT || getCorners().getB().getY() >= MAX_BUILD_HEIGHT) {
MessageUtils.format(BUILDER_BUILDING_TOO_HIGH).sendTo(colony).forAllPlayers();
return;
} else if (getPosition().getY() <= MIN_BUILD_HEIGHT) {
MessageUtils.format(BUILDER_BUILDING_TOO_LOW).sendTo(colony).forAllPlayers();
return;
}
if (!builder.equals(BlockPos.ZERO)) {
final IBuilding building = colony.getBuildingManager().getBuilding(builder);
if (building instanceof AbstractBuildingStructureBuilder && (building.getBuildingLevel() >= workOrder.getTargetLevel() || canBeBuiltByBuilder(workOrder.getTargetLevel()))) {
workOrder.setClaimedBy(builder);
} else {
MessageUtils.format(BUILDER_NECESSARY, Integer.toString(workOrder.getTargetLevel())).sendTo(colony).forAllPlayers();
return;
}
}
colony.getWorkManager().addWorkOrder(workOrder, false);
colony.getProgressManager().progressWorkOrderPlacement(workOrder);
if (workOrder.getID() != 0) {
MessageUtils.format(WORK_ORDER_CREATED, workOrder.getDisplayName(), colony.getName(), workOrder.getLocation().getX(), workOrder.getLocation().getY(), workOrder.getLocation().getZ()).sendTo(colony).forAllPlayers();
}
markDirty();
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.
the class AbstractEntityAIStructureWithWorkOrder method loadStructure.
/**
* Load the structure into the AI.
*/
private void loadStructure() {
final IWorkOrder workOrder = job.getWorkOrder();
if (workOrder == null) {
return;
}
final BlockPos pos = workOrder.getLocation();
if (workOrder instanceof WorkOrderBuilding && worker.getCitizenColonyHandler().getColony().getBuildingManager().getBuilding(pos) == null) {
Log.getLogger().warn("AbstractBuilding does not exist - removing build request");
worker.getCitizenColonyHandler().getColony().getWorkManager().removeWorkOrder(workOrder);
return;
}
final int tempRotation = workOrder.getRotation();
final boolean removal = workOrder.getWorkOrderType() == WorkOrderType.REMOVE;
loadStructure(workOrder.getStructureName(), tempRotation, pos, workOrder.isMirrored(), removal);
workOrder.setCleared(false);
workOrder.setRequested(removal);
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuilding in project minecolonies by Minecolonies.
the class BuildToolPasteMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
final StructureName sn = new StructureName(structureName);
final ServerPlayerEntity player = ctxIn.getSender();
if (!Structures.hasMD5(sn)) {
MessageUtils.format(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!")).sendTo(player);
return;
}
if (player.isCreative()) {
if (isHut) {
handleHut(CompatibilityUtils.getWorldFromEntity(player), player, sn, rotation, pos, mirror, state, complete);
CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
@Nullable final IBuilding building = IColonyManager.getInstance().getBuilding(CompatibilityUtils.getWorldFromEntity(player), pos);
if (building != null) {
final WorkOrderBuilding workOrder = WorkOrderBuilding.create(WorkOrderType.BUILD, building);
ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorldFromEntity(player));
}
} else {
StructurePlacementUtils.loadAndPlaceStructureWithRotation(ctxIn.getSender().level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, ctxIn.getSender());
}
} else if (structureName.contains("supply")) {
if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) > 0 && !MineColonies.getConfig().getServer().allowInfiniteSupplyChests.get() && !isFreeInstantPlacementMH(player)) {
MessageUtils.format(WARNING_SUPPLY_CHEST_ALREADY_PLACED).sendTo(player);
return;
}
Predicate<ItemStack> searchPredicate = stack -> !stack.isEmpty();
if (structureName.contains("supplyship")) {
searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyChest), true, false));
}
if (structureName.contains("supplycamp")) {
searchPredicate = searchPredicate.and(stack -> ItemStackUtils.compareItemStacksIgnoreStackSize(stack, new ItemStack(ModItems.supplyCamp), true, false));
}
if (isFreeInstantPlacementMH(player)) {
searchPredicate = searchPredicate.and(stack -> stack.hasTag() && stack.getTag().get(PLACEMENT_NBT) != null && stack.getTag().getString(PLACEMENT_NBT).equals(INSTANT_PLACEMENT));
}
final int slot = InventoryUtils.findFirstSlotInItemHandlerNotEmptyWith(new InvWrapper(player.inventory), searchPredicate);
if (slot != -1 && !ItemStackUtils.isEmpty(player.inventory.removeItemNoUpdate(slot))) {
if (player.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) < 1) {
MessageUtils.format(PROGRESS_SUPPLY_CHEST_PLACED).sendTo(player);
player.awardStat(Stats.ITEM_USED.get(ModItems.supplyChest), 1);
AdvancementTriggers.PLACE_SUPPLY.trigger(player);
}
CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, structureName, pos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, !complete, player);
} else {
MessageUtils.format(WARNING_REMOVING_SUPPLY_CHEST).sendTo(player);
}
}
}
Aggregations