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