From f6e756503d54fbbcc459b7891c35c980423c3297 Mon Sep 17 00:00:00 2001 From: kitkatod <100255227+kitkatod@users.noreply.github.com> Date: Mon, 20 May 2024 22:46:02 -0700 Subject: [PATCH 1/5] Add glow_item_frame to list of entities that are copied when creating schematic. --- .../denizenscript/denizen/utilities/blocks/CuboidBlockSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java index dd81b750e8..61fa46f387 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java @@ -197,7 +197,7 @@ public static BlockFace rotateFaceOne(BlockFace face) { } } - public static HashSet copyTypes = new HashSet<>(Arrays.asList(EntityType.PAINTING, EntityType.ITEM_FRAME, EntityType.ARMOR_STAND)); + public static HashSet copyTypes = new HashSet<>(Arrays.asList(EntityType.PAINTING, EntityType.ITEM_FRAME, EntityType.ARMOR_STAND, EntityType.GLOW_ITEM_FRAME)); static { if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_20)) { From 63ca49a6435c68b7b6652edf8f14692a78427948 Mon Sep 17 00:00:00 2001 From: kitkatod <100255227+kitkatod@users.noreply.github.com> Date: Mon, 20 May 2024 22:50:12 -0700 Subject: [PATCH 2/5] Fix for entity offset position and yaw being incorrect when flipping. --- .../utilities/blocks/CuboidBlockSet.java | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java index 61fa46f387..28c6e50b07 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java @@ -383,7 +383,7 @@ public void rotateOne() { blocks = bd; } - public void flipEntities(int offsetMultiplier_X, int offsetMultiplier_Z) { + public void flipEntitiesX() { if (entities == null) { return; } @@ -391,21 +391,30 @@ public void flipEntities(int offsetMultiplier_X, int offsetMultiplier_Z) { for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { int rotation = data.getElement("rotation").asInt(); LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); - float newYaw = offset.getYaw(); - if (offsetMultiplier_X == -1) { - newYaw = -1 * (offset.getYaw() - 90) + 270; - } else if (offsetMultiplier_Z == -1) { - newYaw = 180 - offset.getYaw(); - } - while (newYaw < 0 || newYaw >= 360) { - if (newYaw >= 360) { - newYaw -= 360; - } else { - newYaw += 360; - } - } - rotation += (offset.getYaw() - newYaw); - offset = new LocationTag((String) null, offset.getX() * offsetMultiplier_X, offset.getY(), offset.getZ() * offsetMultiplier_Z, newYaw, offset.getPitch()); + int newYaw = normalizeAngle((int)offset.getYaw() - rotation); + newYaw = -(newYaw - 90) + 270; + rotation = normalizeAngle((int)(newYaw - offset.getYaw())); + offset.setX(-offset.getX() + 1); + data = data.duplicate(); + data.putObject("offset", offset); + data.putObject("rotation", new ElementTag(rotation)); + outEntities.addObject(data); + } + entities = outEntities; + } + + public void flipEntitiesZ() { + if (entities == null) { + return; + } + ListTag outEntities = new ListTag(); + for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { + int rotation = data.getElement("rotation").asInt(); + LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); + int newYaw = normalizeAngle((int)offset.getYaw() - rotation); + newYaw = 180 - newYaw; + rotation = normalizeAngle((int)(newYaw - offset.getYaw())); + offset.setZ(-offset.getZ() + 1); data = data.duplicate(); data.putObject("offset", offset); data.putObject("rotation", new ElementTag(rotation)); @@ -414,8 +423,19 @@ public void flipEntities(int offsetMultiplier_X, int offsetMultiplier_Z) { entities = outEntities; } + public int normalizeAngle(int angle){ + while (angle < 0 || angle >= 360) { + if (angle >= 360) { + angle -= 360; + } else { + angle += 360; + } + } + return angle; + } + public void flipX() { - flipEntities(-1, 1); + flipEntitiesX(); FullBlockData[] bd = new FullBlockData[blocks.length]; int index = 0; center_x = x_width - center_x - 1; @@ -444,7 +464,7 @@ public void flipY() { } public void flipZ() { - flipEntities(1, -1); + flipEntitiesZ(); FullBlockData[] bd = new FullBlockData[blocks.length]; int index = 0; center_z = z_height - center_z - 1; From 65afc45e54fd06832b6a950eafe8adc58aad73f9 Mon Sep 17 00:00:00 2001 From: kitkatod <100255227+kitkatod@users.noreply.github.com> Date: Tue, 21 May 2024 18:33:19 -0700 Subject: [PATCH 3/5] Fix for entity yaw being incorrect when yaw is not a multiple of 90. Now functions as expected for any valid yaw value. Update entity rotation mechanism and entity yaw anytime schematic is flipped or rotated, instead of calculating when pasting "how much entity has rotated since creation" then applying. Remove an offset compensation for hanging entities being weird. During testing this has not caused any issues, unsure if this was an issue previously due to incorrect entity rotations. --- .../utilities/blocks/CuboidBlockSet.java | 103 ++++++++++-------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java index 28c6e50b07..897de4fd1c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java @@ -218,7 +218,6 @@ public void buildEntities(AreaContainmentObject area, Location center) { } MapTag data = new MapTag(); data.putObject("entity", entTag.describe(null)); - data.putObject("rotation", new ElementTag(0)); Vector offset = ent.getLocation().toVector().subtract(center.toVector()); data.putObject("offset", new LocationTag((String) null, offset.getX(), offset.getY(), offset.getZ(), ent.getLocation().getYaw(), ent.getLocation().getPitch())); entities.addObject(data); @@ -234,38 +233,17 @@ public void pasteEntities(LocationTag relative) { for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { try { LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); - int rotation = data.getElement("rotation").asInt(); EntityTag entity = data.getObjectAs("entity", EntityTag.class, CoreUtilities.noDebugContext); if (entity == null || offset == null) { continue; } entity = entity.duplicate(); offset = offset.clone(); - if (rotation != 0) { - ArrayList mechs = new ArrayList<>(entity.getWaitingMechanisms().size()); - for (Mechanism mech : entity.getWaitingMechanisms()) { - if (mech.getName().equals("rotation")) { - String rotationName = mech.getValue().asString(); - BlockFace face = BlockFace.valueOf(rotationName.toUpperCase()); - for (int i = 0; i < rotation; i += 90) { - face = rotateFaceOne(face); - } - offset.add(face.getDirection().multiply(0.1)); // Compensate for hanging locations being very stupid - mechs.add(new Mechanism("rotation", new ElementTag(face), CoreUtilities.noDebugContext)); - } - else { - mechs.add(new Mechanism(mech.getName(), mech.value, CoreUtilities.noDebugContext)); - } - } - entity.mechanisms = mechs; - } - else { - for (Mechanism mechanism : entity.mechanisms) { - mechanism.context = CoreUtilities.noDebugContext; - } + for (Mechanism mechanism : entity.mechanisms) { + mechanism.context = CoreUtilities.noDebugContext; } Location spawnLoc = relative.clone().add(offset); - spawnLoc.setYaw(offset.getYaw() - rotation); + spawnLoc.setYaw(offset.getYaw()); spawnLoc.setPitch(offset.getPitch()); entity.spawnAt(spawnLoc); } @@ -349,15 +327,24 @@ public void rotateEntitiesOne() { ListTag outEntities = new ListTag(); for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); - int rotation = data.getElement("rotation").asInt(); - offset = new LocationTag((String) null, offset.getZ(), offset.getY(), -offset.getX() + 1, offset.getYaw(), offset.getPitch()); - rotation += 90; - while (rotation >= 360) { - rotation -= 360; + EntityTag entity = data.getObjectAs("entity", EntityTag.class, CoreUtilities.noDebugContext); + offset = new LocationTag((String) null, offset.getZ(), offset.getY(), -offset.getX() + 1, normalizeYaw(offset.getYaw() - 90), offset.getPitch()); + ArrayList mechs = new ArrayList<>(entity.getWaitingMechanisms().size()); + for (Mechanism mech : entity.getWaitingMechanisms()) { + if (mech.getName().equals("rotation")) { + String rotationName = mech.getValue().asString(); + BlockFace face = BlockFace.valueOf(rotationName.toUpperCase()); + face = rotateFaceOne(face); + mechs.add(new Mechanism("rotation", new ElementTag(face), CoreUtilities.noDebugContext)); + } + else { + mechs.add(new Mechanism(mech.getName(), mech.value, CoreUtilities.noDebugContext)); + } } + entity.mechanisms = mechs; data = data.duplicate(); data.putObject("offset", offset); - data.putObject("rotation", new ElementTag(rotation)); + data.putObject("entity", entity); outEntities.addObject(data); } entities = outEntities; @@ -389,15 +376,26 @@ public void flipEntitiesX() { } ListTag outEntities = new ListTag(); for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { - int rotation = data.getElement("rotation").asInt(); + EntityTag entity = data.getObjectAs("entity", EntityTag.class, CoreUtilities.noDebugContext); LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); - int newYaw = normalizeAngle((int)offset.getYaw() - rotation); - newYaw = -(newYaw - 90) + 270; - rotation = normalizeAngle((int)(newYaw - offset.getYaw())); + offset.setYaw(normalizeYaw(180 - (offset.getYaw() - 90) + 90)); offset.setX(-offset.getX() + 1); + ArrayList mechs = new ArrayList<>(entity.getWaitingMechanisms().size()); + for (Mechanism mech : entity.getWaitingMechanisms()) { + if (mech.getName().equals("rotation")) { + String rotationName = mech.getValue().asString(); + BlockFace face = BlockFace.valueOf(rotationName.toUpperCase()); + face = FullBlockData.flipFaceX(face); + mechs.add(new Mechanism("rotation", new ElementTag(face), CoreUtilities.noDebugContext)); + } + else { + mechs.add(new Mechanism(mech.getName(), mech.value, CoreUtilities.noDebugContext)); + } + } + entity.mechanisms = mechs; data = data.duplicate(); data.putObject("offset", offset); - data.putObject("rotation", new ElementTag(rotation)); + data.putObject("entity", entity); outEntities.addObject(data); } entities = outEntities; @@ -409,29 +407,40 @@ public void flipEntitiesZ() { } ListTag outEntities = new ListTag(); for (MapTag data : entities.filter(MapTag.class, CoreUtilities.noDebugContext)) { - int rotation = data.getElement("rotation").asInt(); + EntityTag entity = data.getObjectAs("entity", EntityTag.class, CoreUtilities.noDebugContext); LocationTag offset = data.getObjectAs("offset", LocationTag.class, CoreUtilities.noDebugContext); - int newYaw = normalizeAngle((int)offset.getYaw() - rotation); - newYaw = 180 - newYaw; - rotation = normalizeAngle((int)(newYaw - offset.getYaw())); offset.setZ(-offset.getZ() + 1); + offset.setYaw(normalizeYaw(180 - offset.getYaw())); + ArrayList mechs = new ArrayList<>(entity.getWaitingMechanisms().size()); + for (Mechanism mech : entity.getWaitingMechanisms()) { + if (mech.getName().equals("rotation")) { + String rotationName = mech.getValue().asString(); + BlockFace face = BlockFace.valueOf(rotationName.toUpperCase()); + face = FullBlockData.flipFaceZ(face); + mechs.add(new Mechanism("rotation", new ElementTag(face), CoreUtilities.noDebugContext)); + } + else { + mechs.add(new Mechanism(mech.getName(), mech.value, CoreUtilities.noDebugContext)); + } + } + entity.mechanisms = mechs; data = data.duplicate(); data.putObject("offset", offset); - data.putObject("rotation", new ElementTag(rotation)); + data.putObject("entity", entity); outEntities.addObject(data); } entities = outEntities; } - public int normalizeAngle(int angle){ - while (angle < 0 || angle >= 360) { - if (angle >= 360) { - angle -= 360; + public float normalizeYaw(float yaw){ + while (yaw < 0 || yaw >= 360) { + if (yaw >= 360) { + yaw -= 360; } else { - angle += 360; + yaw += 360; } } - return angle; + return yaw; } public void flipX() { From 26b6c317cf3a505b3fbc2c393279f5e00d0e7922 Mon Sep 17 00:00:00 2001 From: kitkatod <100255227+kitkatod@users.noreply.github.com> Date: Tue, 21 May 2024 18:49:41 -0700 Subject: [PATCH 4/5] Return original BlockFace if rotating a non-rotatable BlockFace. --- .../denizenscript/denizen/utilities/blocks/CuboidBlockSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java index 897de4fd1c..50c0defaf2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/CuboidBlockSet.java @@ -193,7 +193,7 @@ public static BlockFace rotateFaceOne(BlockFace face) { case SOUTH_EAST: return BlockFace.NORTH_EAST; default: - return BlockFace.SELF; + return face; } } From cfac7fe9064823cbc8038f5cf5bce18fa7804a53 Mon Sep 17 00:00:00 2001 From: kitkatod <100255227+kitkatod@users.noreply.github.com> Date: Tue, 21 May 2024 18:58:31 -0700 Subject: [PATCH 5/5] Update Schematic command meta for supported entity types. --- .../denizen/scripts/commands/world/SchematicCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SchematicCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SchematicCommand.java index 6bc72c281c..8e31fc3f63 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SchematicCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/SchematicCommand.java @@ -104,7 +104,7 @@ public void run(ReplaceableTagEvent event) { // This takes an optional duration as "fake_duration" for how long the fake blocks should remain. // // The "create" and "paste" options allow the "entities" argument to be specified - when used, entities will be copied or pasted. - // At current time, entity types included will be: Paintings, ItemFrames, ArmorStands. + // At current time, entity types included will be: Paintings, ItemFrames, GlowItemFrames, ArmorStands, and DisplayEntities. // // The "create" option allows the "flags" argument to be specified - when used, block location flags will be copied. //