Search in sources :

Example 6 with WorkOrderBuildBuilding

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();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with WorkOrderBuildBuilding

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");
        }
    }
}
Also used : WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.ldtteam.structurize.management.StructureName) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Predicate(java.util.function.Predicate)

Example 8 with WorkOrderBuildBuilding

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");
        }
    }
}
Also used : WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.ldtteam.structurize.management.StructureName) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Predicate(java.util.function.Predicate)

Aggregations

WorkOrderBuildBuilding (com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding)8 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)4 WorkOrderBuildRemoval (com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval)4 BlockPos (net.minecraft.util.math.BlockPos)4 NotNull (org.jetbrains.annotations.NotNull)4 StructureName (com.ldtteam.structurize.management.StructureName)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)2 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)2 Predicate (java.util.function.Predicate)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 Nullable (org.jetbrains.annotations.Nullable)2