use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding in project minecolonies by Minecolonies.
the class AbstractBuilding method requestWorkOrder.
/**
* Adds work orders to the {@link Colony#getWorkManager()}.
*
* @param level Desired level.
* @param builder the assigned builder.
*/
protected void requestWorkOrder(final int level, final BlockPos builder, final boolean removal) {
for (@NotNull final WorkOrderBuildBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuildBuilding.class)) {
if (o.getSchematicLocation().equals(getID())) {
return;
}
}
WorkOrderBuild workOrder;
if (removal) {
if (!canDeconstruct()) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.cantdeconstruct");
return;
}
workOrder = new WorkOrderBuildRemoval(this, level);
} else {
workOrder = new WorkOrderBuildBuilding(this, level);
}
if (!removal && !canBeBuiltByBuilder(level) && !workOrder.canBeResolved(colony, level)) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
return;
}
if (workOrder.tooFarFromAnyBuilder(colony, level) && builder.equals(BlockPos.ZERO)) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuilderstoofar");
return;
}
if (getCorners().getA().getY() >= MAX_BUILD_HEIGHT || getCorners().getB().getY() >= MAX_BUILD_HEIGHT) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoohigh");
return;
} else if (getPosition().getY() <= MIN_BUILD_HEIGHT) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoolow");
return;
}
if (!builder.equals(BlockPos.ZERO)) {
final IBuilding building = colony.getBuildingManager().getBuilding(builder);
if (building instanceof AbstractBuildingStructureBuilder && (building.getBuildingLevel() >= level || canBeBuiltByBuilder(level))) {
workOrder.setClaimedBy(builder);
} else {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
return;
}
}
colony.getWorkManager().addWorkOrder(workOrder, false);
colony.getProgressManager().progressWorkOrderPlacement(workOrder);
if (workOrder.getID() != 0) {
LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.workorderadded", workOrder.getDisplayName(), colony.getName(), workOrder.getSchematicLocation().getX(), workOrder.getSchematicLocation().getY(), workOrder.getSchematicLocation().getZ());
}
markDirty();
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding 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)) {
player.sendMessage(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!"), player.getUUID());
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 WorkOrderBuildBuilding workOrder = new WorkOrderBuildBuilding(building, 1);
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)) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.error.supplyChestAlreadyPlaced");
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) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.progress.supplies_placed");
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 {
LanguageHandler.sendPlayerMessage(player, "item.supplyChestDeployer.missing");
}
}
}
use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding in project minecolonies by ldtteam.
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)) {
player.sendMessage(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!"), player.getUUID());
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 WorkOrderBuildBuilding workOrder = new WorkOrderBuildBuilding(building, 1);
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)) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.error.supplyChestAlreadyPlaced");
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) {
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.progress.supplies_placed");
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 {
LanguageHandler.sendPlayerMessage(player, "item.supplyChestDeployer.missing");
}
}
}
Aggregations