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);
}
}
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);
}
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);
}
}
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());
}
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());
}
Aggregations