Search in sources :

Example 1 with WorkOrderDecoration

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

the class BuildToolPlaceMessage method handleDecoration.

/**
 * Creates the {@link WorkOrderDecoration} to start building the decoration.
 *
 * @param world         The world the decoration is being built in.
 * @param player        The player who placed the decoration.
 * @param sn            The name of the structure.
 * @param workOrderName The style of the decoration.
 * @param rotation      The number of times the decoration is rotated.
 * @param buildPos      The location the decoration will be built.
 * @param mirror        Whether or not the strcture is mirrored.
 */
private static void handleDecoration(@NotNull final World world, @NotNull final PlayerEntity player, final StructureName sn, final String workOrderName, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror, BlockPos builder) {
    @Nullable final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, buildPos);
    if (colony != null && colony.getPermissions().hasPermission(player, Action.PLACE_HUTS)) {
        String schem = sn.toString();
        String woName = workOrderName;
        if (!schem.contains("cache")) {
            if (schem.matches("^.*[a-zA-Z_-]\\d$")) {
                schem = schem.replaceAll("\\d$", "");
                schem += '1';
            }
            if (woName.matches("^.*[a-zA-Z_-]\\d$")) {
                woName = woName.replaceAll("\\d$", "");
                woName += '1';
            }
        }
        WorkOrderDecoration woDeco = WorkOrderDecoration.create(WorkOrderType.BUILD, schem, WordUtils.capitalizeFully(woName), buildPos, rotation, mirror, 0);
        if (!builder.equals(BlockPos.ZERO)) {
            woDeco.setClaimedBy(builder);
        }
        colony.getWorkManager().addWorkOrder(woDeco, false);
    } else {
        SoundUtils.playErrorSound(player, player.blockPosition());
        Log.getLogger().error("handleDecoration: Could not build " + sn, new Exception());
    }
}
Also used : WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) IColony(com.minecolonies.api.colony.IColony) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with WorkOrderDecoration

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

the class DecorationBuildRequestMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
    if (colony == null) {
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    // Verify player has permission to change this hut its settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
    if (entity instanceof TileEntityDecorationController) {
        final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderDecoration).filter(entry -> entry.getValue().getLocation().equals(pos)).findFirst();
        if (wo.isPresent()) {
            colony.getWorkManager().removeWorkOrder(wo.get().getKey());
            return;
        }
        int difference = 0;
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof BlockDecorationController)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
                    return;
                }
                final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    difference = worldRotation - structureRotation;
                } else {
                    difference = 4 + worldRotation - structureRotation;
                }
            }
        }
        final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
        final int currentLevel = ((TileEntityDecorationController) entity).getTier();
        WorkOrderDecoration order;
        if (level > currentLevel) {
            order = WorkOrderDecoration.create(WorkOrderType.UPGRADE, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        } else if (level == currentLevel) {
            order = WorkOrderDecoration.create(WorkOrderType.REPAIR, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        } else {
            order = WorkOrderDecoration.create(WorkOrderType.BUILD, name + level, WordUtils.capitalizeFully(displayName), pos, difference, state.getValue(BlockDecorationController.MIRROR), currentLevel);
        }
        colony.getWorkManager().addWorkOrder(order, false);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) WordUtils(org.apache.commons.lang3.text.WordUtils) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) WorkOrderType(com.minecolonies.api.colony.workorders.WorkOrderType) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) WorkOrderDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderDecoration) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler)

Aggregations

IColony (com.minecolonies.api.colony.IColony)2 WorkOrderDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderDecoration)2 Nullable (org.jetbrains.annotations.Nullable)2 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)1 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)1 IColonyManager (com.minecolonies.api.colony.IColonyManager)1 Action (com.minecolonies.api.colony.permissions.Action)1 IWorkOrder (com.minecolonies.api.colony.workorders.IWorkOrder)1 WorkOrderType (com.minecolonies.api.colony.workorders.WorkOrderType)1 IMessage (com.minecolonies.api.network.IMessage)1 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)1 Log (com.minecolonies.api.util.Log)1 BlockDecorationController (com.minecolonies.coremod.blocks.BlockDecorationController)1 TileEntityDecorationController (com.minecolonies.coremod.tileentities.TileEntityDecorationController)1 Map (java.util.Map)1 Optional (java.util.Optional)1 BlockState (net.minecraft.block.BlockState)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 TileEntity (net.minecraft.tileentity.TileEntity)1