Search in sources :

Example 31 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings 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)

Example 32 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project Structurize by ldtteam.

the class StructurePlacementUtils method unloadStructure.

/**
 * Unload a structure at a certain location.
 *
 * @param world    the world.
 * @param startPos      the position.
 * @param name    the name.
 * @param rotation the rotation.
 * @param mirror   the mirror.
 */
public static void unloadStructure(@NotNull final World world, @NotNull final BlockPos startPos, @NotNull final String name, final Rotation rotation, @NotNull final Mirror mirror) {
    @NotNull final IStructureHandler structure = new CreativeStructureHandler(world, startPos, name, new PlacementSettings(mirror, rotation), false);
    structure.getBluePrint().rotateWithMirror(rotation, mirror, world);
    @NotNull final StructurePlacer placer = new StructurePlacer(structure);
    placer.executeStructureStep(world, null, new BlockPos(0, 0, 0), StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().increment((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock), true);
}
Also used : TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation) World(net.minecraft.world.World) AirBlock(net.minecraft.block.AirBlock) BlockPos(net.minecraft.util.math.BlockPos) Mirror(net.minecraft.util.Mirror) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Manager(com.ldtteam.structurize.management.Manager) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) Rotation(net.minecraft.util.Rotation) Log(com.ldtteam.structurize.api.util.Log) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) AirBlock(net.minecraft.block.AirBlock) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project Structurize by ldtteam.

the class StructurePlacementUtils method loadAndPlaceStructureWithRotation.

/**
 * Load a structure into this world
 * and place it in the right position and rotation.
 *
 * @param worldObj the world to load it in
 * @param blueprint the structures blueprint
 * @param pos      coordinates
 * @param rotation the rotation.
 * @param mirror   the mirror used.
 * @param fancyPlacement if fancy or complete.
 * @param player   the placing player.
 */
public static void loadAndPlaceStructureWithRotation(final World worldObj, @NotNull final Blueprint blueprint, @NotNull final BlockPos pos, final Rotation rotation, @NotNull final Mirror mirror, final boolean fancyPlacement, final ServerPlayerEntity player) {
    try {
        @NotNull final IStructureHandler structure = new CreativeStructureHandler(worldObj, pos, blueprint, new PlacementSettings(mirror, rotation), fancyPlacement);
        if (fancyPlacement) {
            structure.fancyPlacement();
        }
        structure.getBluePrint().rotateWithMirror(rotation, mirror, worldObj);
        @NotNull final StructurePlacer instantPlacer = new StructurePlacer(structure);
        Manager.addToQueue(new TickedWorldOperation(instantPlacer, player));
    } catch (final IllegalStateException e) {
        Log.getLogger().warn("Could not load structure!", e);
    }
}
Also used : CreativeStructureHandler(com.ldtteam.structurize.placement.structure.CreativeStructureHandler) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) NotNull(org.jetbrains.annotations.NotNull) TickedWorldOperation(com.ldtteam.structurize.util.TickedWorldOperation)

Example 34 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project Structurize by ldtteam.

the class WindowShapeTool method updateRotation.

/**
 * Updates the rotation of the structure depending on the input.
 *
 * @param rotation the rotation to be set.
 */
private static void updateRotation(final int rotation) {
    final PlacementSettings settings = new PlacementSettings();
    switch(rotation) {
        case ROTATE_ONCE:
            settings.setRotation(Rotation.CLOCKWISE_90);
            break;
        case ROTATE_TWICE:
            settings.setRotation(Rotation.CLOCKWISE_180);
            break;
        case ROTATE_THREE_TIMES:
            settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            break;
        default:
            settings.setRotation(Rotation.NONE);
    }
    Settings.instance.setRotation(rotation);
    settings.setMirror(Settings.instance.getMirror());
}
Also used : PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 35 with PlacementSettings

use of com.ldtteam.structurize.util.PlacementSettings in project Structurize by ldtteam.

the class WindowBuildTool method updateRotation.

/**
 * Updates the rotation of the structure depending on the input.
 *
 * @param rotation the rotation to be set.
 */
private static void updateRotation(final int rotation) {
    final PlacementSettings settings = new PlacementSettings();
    switch(rotation) {
        case ROTATE_RIGHT:
            settings.setRotation(Rotation.CLOCKWISE_90);
            break;
        case ROTATE_180:
            settings.setRotation(Rotation.CLOCKWISE_180);
            break;
        case ROTATE_LEFT:
            settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            break;
        default:
            settings.setRotation(Rotation.NONE);
    }
    Settings.instance.setRotation(rotation);
    settings.setMirror(Settings.instance.getMirror());
}
Also used : PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Aggregations

PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)45 BlockPos (net.minecraft.util.math.BlockPos)29 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)21 NotNull (org.jetbrains.annotations.NotNull)15 StructurePlacer (com.ldtteam.structurize.placement.StructurePlacer)12 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)12 World (net.minecraft.world.World)12 TileEntity (net.minecraft.tileentity.TileEntity)11 ItemStack (net.minecraft.item.ItemStack)10 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)9 StructureName (com.ldtteam.structurize.management.StructureName)9 StructurePhasePlacementResult (com.ldtteam.structurize.placement.StructurePhasePlacementResult)8 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)7 TickedWorldOperation (com.ldtteam.structurize.util.TickedWorldOperation)7 Mirror (net.minecraft.util.Mirror)7 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)6 NULL_POS (com.ldtteam.structurize.placement.AbstractBlueprintIterator.NULL_POS)6 BlockPlacementResult (com.ldtteam.structurize.placement.BlockPlacementResult)6 IColonyView (com.minecolonies.api.colony.IColonyView)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6