use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class WindowBuildTool method adjustToGroundOffset.
/**
* Detects the intended ground level via tag and offsets the blueprint accordingly
*/
private void adjustToGroundOffset() {
final Blueprint blueprint = Settings.instance.getActiveStructure();
if (blueprint != null) {
int groundOffset;
switch(groundstyle) {
case GROUNDSTYLE_LEGACY_CAMP:
groundOffset = BlueprintTagUtils.getGroundAnchorOffsetFromGroundLevels(blueprint, BlueprintTagUtils.getNumberOfGroundLevels(blueprint, 1));
break;
case GROUNDSTYLE_LEGACY_SHIP:
groundOffset = BlueprintTagUtils.getGroundAnchorOffsetFromGroundLevels(blueprint, BlueprintTagUtils.getNumberOfGroundLevels(blueprint, 3));
break;
case GROUNDSTYLE_RELATIVE:
default:
groundOffset = BlueprintTagUtils.getGroundAnchorOffset(blueprint, 1);
break;
}
// compensate for clicking the top face of the ground block
--groundOffset;
Settings.instance.setGroundOffset(groundOffset);
}
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class ItemScanTool method saveStructure.
/**
* Scan the structure and save it to the disk.
*
* @param world Current world.
* @param from First corner.
* @param to Second corner.
* @param player causing this action.
* @param name the name of it.
* @param saveEntities whether to scan in entities
*/
public static void saveStructure(@NotNull final World world, @NotNull final BlockPos from, @NotNull final BlockPos to, @NotNull final PlayerEntity player, final String name, final boolean saveEntities, final Optional<BlockPos> anchorPos) {
if (anchorPos.isPresent()) {
if (!BlockPosUtil.isInbetween(anchorPos.get(), from, to)) {
LanguageHandler.sendPlayerMessage(player, ANCHOR_POS_OUTSIDE_SCHEMATIC);
return;
}
}
final BlockPos blockpos = new BlockPos(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), Math.min(from.getZ(), to.getZ()));
final BlockPos blockpos1 = new BlockPos(Math.max(from.getX(), to.getX()), Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ()));
final BlockPos size = blockpos1.subtract(blockpos).offset(1, 1, 1);
if (size.getX() * size.getY() * size.getZ() > Structurize.getConfig().getServer().schematicBlockLimit.get()) {
LanguageHandler.sendPlayerMessage(player, MAX_SCHEMATIC_SIZE_REACHED, Structurize.getConfig().getServer().schematicBlockLimit.get());
return;
}
final long currentMillis = System.currentTimeMillis();
final String currentMillisString = Long.toString(currentMillis);
final String fileName;
if (name == null || name.isEmpty()) {
fileName = LanguageHandler.format("item.sceptersteel.scanformat", "", currentMillisString);
} else {
fileName = name;
}
final Blueprint bp = BlueprintUtil.createBlueprint(world, blockpos, saveEntities, (short) size.getX(), (short) size.getY(), (short) size.getZ(), fileName, anchorPos);
if (!anchorPos.isPresent() && bp.getPrimaryBlockOffset().equals(new BlockPos(bp.getSizeX() / 2, 0, bp.getSizeZ() / 2))) {
final List<BlockInfo> list = bp.getBlockInfoAsList().stream().filter(blockInfo -> blockInfo.hasTileEntityData() && blockInfo.getTileEntityData().contains(TAG_BLUEPRINTDATA)).collect(Collectors.toList());
if (list.size() > 1) {
player.sendMessage(new TranslationTextComponent("com.ldtteam.structurize.gui.scantool.scanbadanchor", fileName), player.getUUID());
}
}
Network.getNetwork().sendToPlayer(new SaveScanMessage(BlueprintUtil.writeBlueprintToNBT(bp), fileName), (ServerPlayerEntity) player);
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class Manager method generateCone.
private static Blueprint generateCone(final int inputHeight, final int width, final BlockState block, final BlockState fillBlock, final boolean hollow, final Shape shape) {
final int height = shape == Shape.DIAMOND ? inputHeight : inputHeight * 2;
final Map<BlockPos, BlockState> posList = new HashMap<>();
for (int x = 0; x < width; x++) {
for (int z = 0; z < width; z++) {
for (int y = 0; y < height; y++) {
final int consideredWidth = (int) (width - y);
int sum = x * x + z * z;
final boolean shouldBeEmpty = sum > (consideredWidth * consideredWidth) / 4 - consideredWidth;
if (sum < (consideredWidth * consideredWidth) / 4 && (!hollow || shouldBeEmpty) && consideredWidth > 0) {
final BlockState blockToUse = shouldBeEmpty ? block : fillBlock;
addPosToList(new BlockPos(width + x, y, width + z), blockToUse, posList);
addPosToList(new BlockPos(width + x, y, width - z), blockToUse, posList);
addPosToList(new BlockPos(width - x, y, width + z), blockToUse, posList);
addPosToList(new BlockPos(width - x, y, width - z), blockToUse, posList);
}
}
}
}
final Blueprint blueprint = new Blueprint((short) (width * 2), (short) height, (short) (width * 2));
posList.forEach(blueprint::addBlockState);
return blueprint;
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class Manager method pasteStructure.
/**
* Paste a structure into the world.
*
* @param server the server world.
* @param pos the position.
* @param width the width.
* @param length the length.
* @param height the height.
* @param frequency the frequency.
* @param equation the equation.
* @param shape the shape.
* @param inputBlock the input block.
* @param inputFillBlock the fill block.
* @param hollow if hollow or not.
* @param player the player.
* @param mirror the mirror.
* @param rotation the rotation.
*/
public static void pasteStructure(final ServerWorld server, final BlockPos pos, final int width, final int length, final int height, final int frequency, final String equation, final Shape shape, final ItemStack inputBlock, final ItemStack inputFillBlock, final boolean hollow, final ServerPlayerEntity player, final Mirror mirror, final Rotation rotation) {
final Blueprint blueprint = Manager.getStructureFromFormula(width, length, height, frequency, equation, shape, inputBlock, inputFillBlock, hollow);
StructurePlacementUtils.loadAndPlaceStructureWithRotation(server, blueprint, pos, rotation, mirror, true, player);
}
use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.
the class Manager method generateWave.
/**
* Generates a wave with the specific size and adds it to the blueprint provided.
*
* @param height the height.
* @param width the width.
* @param length the length.
* @param block the block to use.
*/
private static Blueprint generateWave(final int height, final int width, final int length, final int frequency, final BlockState block, final boolean flat) {
final Map<BlockPos, BlockState> posList = new HashMap<>();
for (int x = 0; x < length; x++) {
for (int z = 0; z < width; z++) {
final double yVal = (flat ? 0 : z) + (double) frequency * Math.sin(x / (double) height);
addPosToList(new BlockPos(x, yVal + frequency, (flat ? 0 : width) + z), block, posList);
if (!flat) {
addPosToList(new BlockPos(x, yVal + frequency, width - z), block, posList);
addPosToList(new BlockPos(x, yVal + width - 1 + frequency, width + z - width + 1), block, posList);
addPosToList(new BlockPos(x, yVal + width - 1 + frequency, width - z + width - 1), block, posList);
}
}
}
final Blueprint blueprint = new Blueprint((short) length, (short) (frequency * 2 + 1 + (!flat ? width * 2 : 0)), (short) (width * 2 + 1));
posList.forEach(blueprint::addBlockState);
return blueprint;
}
Aggregations