From 5e9227d4b17963195f38bb67d08121aba063b0af Mon Sep 17 00:00:00 2001 From: goodroach Date: Fri, 24 Nov 2023 03:17:40 -1000 Subject: [PATCH 1/7] add trackedlocations --- .../async/rotation/RotationTask.java | 7 +++ .../async/translation/TranslationTask.java | 9 ++- .../movecraft/craft/BaseCraft.java | 16 ++++++ .../movecraft/TrackedLocation.java | 57 +++++++++++++++++++ .../countercraft/movecraft/craft/Craft.java | 8 +++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java index ff2553f1b..b3c36d360 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java @@ -21,6 +21,7 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; +import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.AsyncTask; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.Craft; @@ -51,6 +52,7 @@ import org.bukkit.inventory.InventoryView; import java.util.HashSet; +import java.util.Iterator; import java.util.Set; import static net.countercraft.movecraft.util.MathUtils.withinWorldBorder; @@ -167,6 +169,11 @@ protected void execute() { parentCraft.getFluidLocations().addAll(newFluidList); } + //Rotates the craft's tracked locations. + Iterator trackedLocations = craft.getTrackedLocations().values().iterator(); + while(trackedLocations.hasNext()) { + trackedLocations.next().rotate(rotation); + } updates.add(new CraftRotateCommand(getCraft(),originPoint, rotation)); //rotate entities in the craft diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index d74640d34..3d541298f 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -3,6 +3,7 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftChunk; import net.countercraft.movecraft.MovecraftLocation; +import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.AsyncTask; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.ChunkManager; @@ -58,8 +59,8 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashSet; +import java.util.Iterator; import java.util.List; -import java.util.Random; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; @@ -393,6 +394,12 @@ else if (world.equals(craft.getWorld()) updates.add(new CraftTranslateCommand(craft, new MovecraftLocation(dx, dy, dz), world)); + //translates the craft's tracked locations. + Iterator trackedLocations = craft.getTrackedLocations().values().iterator(); + while(trackedLocations.hasNext()) { + trackedLocations.next().translate(dx, dy, dz); + } + //prevents torpedo and rocket pilots if (!(craft instanceof SinkingCraft && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS)) && craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) { diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java index 90266b0b2..ad268bce9 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java @@ -4,6 +4,7 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; +import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.rotation.RotationTask; import net.countercraft.movecraft.async.translation.TranslationTask; import net.countercraft.movecraft.config.Settings; @@ -25,6 +26,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -78,6 +80,7 @@ public abstract class BaseCraft implements Craft { private String name = ""; @NotNull private MovecraftLocation lastTranslation = new MovecraftLocation(0, 0, 0); + private Map trackedLocations = new HashMap<>(); public BaseCraft(@NotNull CraftType type, @NotNull World world) { this.type = type; @@ -598,4 +601,17 @@ public void setTotalFuel(double fuel) { public double getTotalFuel() { return totalFuel; } + + @Override + public Map getTrackedLocations() {return trackedLocations;} + + @Override + public void addTrackedLocation(NamespacedKey key, MovecraftLocation location) { + trackedLocations.put(key, new TrackedLocation(getHitBox().getMidPoint(), location)); + } + + @Override + public void removeTrackedLocation(NamespacedKey key) { + trackedLocations.remove(key); + } } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java new file mode 100644 index 000000000..87b73b681 --- /dev/null +++ b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java @@ -0,0 +1,57 @@ +package net.countercraft.movecraft; + +import org.bukkit.World; +import org.jetbrains.annotations.NotNull; + +public class TrackedLocation { + private int posX; + private int posY; + private int posZ; + private MovecraftLocation origin; + + /** + * Creates a new TrackedLocation instance which tracks a location about an origin. + * @param origin The origin point at which the tracked location rotates about. + * @param location The absolute location to track. + */ + public TrackedLocation(@NotNull MovecraftLocation origin, @NotNull MovecraftLocation location) { + this.origin = origin; + posX = location.getX() - origin.getX(); + posY = location.getY() - origin.getY(); + posZ = location.getZ() - origin.getZ(); + } + + /** + * Moves the origin point of the tracked location + */ + public void translate(int dx, int dy, int dz) { + origin = new MovecraftLocation(origin.getX() + dx, origin.getY() + dy, origin.getZ() + dz); + } + + /** + * Rotates the stored location about the origin point location. + * @param rotation A clockwise or counter-clockwise direction to rotate. + */ + public void rotate(MovecraftRotation rotation) { + int newX; + int newZ; + if (rotation == MovecraftRotation.CLOCKWISE) { + newX = posZ + origin.getX(); + newZ = -posX + origin.getZ(); + } else if (rotation == MovecraftRotation.ANTICLOCKWISE) { + newX = -posZ + origin.getX(); + newZ = posX + origin.getZ(); + } else return; + + posX = newX; + posZ = newZ; + } + + /** + * Gets the stored location. + * @return Returns the location. + */ + public MovecraftLocation getLocation() { + return new MovecraftLocation(posX + origin.getX(), posY + origin.getY(), posZ + origin.getZ()); + } +} diff --git a/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java b/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java index c4b058e4c..0c69cd555 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java @@ -20,6 +20,7 @@ import net.countercraft.movecraft.CruiseDirection; import net.countercraft.movecraft.MovecraftLocation; import net.countercraft.movecraft.MovecraftRotation; +import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.craft.type.CraftType; import net.countercraft.movecraft.processing.MovecraftWorld; import net.countercraft.movecraft.util.Counter; @@ -28,6 +29,7 @@ import net.kyori.adventure.audience.Audience; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; @@ -263,4 +265,10 @@ default void setLastDZ(int dZ){} double getTotalFuel (); void setTotalFuel (double fuel); + + Map getTrackedLocations(); + + void addTrackedLocation(NamespacedKey key, MovecraftLocation location); + + void removeTrackedLocation(NamespacedKey key); } From 5b5b349003a603abcbf142c1745018fd691d3d54 Mon Sep 17 00:00:00 2001 From: goodroach Date: Wed, 6 Mar 2024 20:25:37 -1000 Subject: [PATCH 2/7] reimplement TrackedLocation to specification --- .../async/rotation/RotationTask.java | 7 +- .../async/translation/TranslationTask.java | 6 -- .../movecraft/craft/BaseCraft.java | 14 +--- .../movecraft/TrackedLocation.java | 84 +++++++++++-------- .../countercraft/movecraft/craft/Craft.java | 8 +- 5 files changed, 55 insertions(+), 64 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java index b3c36d360..4ed203c4c 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java @@ -170,9 +170,10 @@ protected void execute() { } //Rotates the craft's tracked locations. - Iterator trackedLocations = craft.getTrackedLocations().values().iterator(); - while(trackedLocations.hasNext()) { - trackedLocations.next().rotate(rotation); + for (Set locations : craft.getTrackedLocations().values()) { + for (TrackedLocation location : locations) { + location.rotate(rotation, originPoint); + } } updates.add(new CraftRotateCommand(getCraft(),originPoint, rotation)); diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 3d541298f..27dfa65d3 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -394,12 +394,6 @@ else if (world.equals(craft.getWorld()) updates.add(new CraftTranslateCommand(craft, new MovecraftLocation(dx, dy, dz), world)); - //translates the craft's tracked locations. - Iterator trackedLocations = craft.getTrackedLocations().values().iterator(); - while(trackedLocations.hasNext()) { - trackedLocations.next().translate(dx, dy, dz); - } - //prevents torpedo and rocket pilots if (!(craft instanceof SinkingCraft && craft.getType().getBoolProperty(CraftType.ONLY_MOVE_PLAYERS)) && craft.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) { diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java index ad268bce9..744110a61 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/craft/BaseCraft.java @@ -80,7 +80,7 @@ public abstract class BaseCraft implements Craft { private String name = ""; @NotNull private MovecraftLocation lastTranslation = new MovecraftLocation(0, 0, 0); - private Map trackedLocations = new HashMap<>(); + private Map> trackedLocations = new HashMap<>(); public BaseCraft(@NotNull CraftType type, @NotNull World world) { this.type = type; @@ -603,15 +603,5 @@ public double getTotalFuel() { } @Override - public Map getTrackedLocations() {return trackedLocations;} - - @Override - public void addTrackedLocation(NamespacedKey key, MovecraftLocation location) { - trackedLocations.put(key, new TrackedLocation(getHitBox().getMidPoint(), location)); - } - - @Override - public void removeTrackedLocation(NamespacedKey key) { - trackedLocations.remove(key); - } + public Map> getTrackedLocations() {return trackedLocations;} } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java index 87b73b681..5908f0753 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java @@ -1,57 +1,69 @@ package net.countercraft.movecraft; -import org.bukkit.World; +import net.countercraft.movecraft.craft.Craft; +import net.countercraft.movecraft.util.MathUtils; import org.jetbrains.annotations.NotNull; public class TrackedLocation { - private int posX; - private int posY; - private int posZ; - private MovecraftLocation origin; + private MovecraftLocation offSet; + private final Craft craft; /** - * Creates a new TrackedLocation instance which tracks a location about an origin. - * @param origin The origin point at which the tracked location rotates about. - * @param location The absolute location to track. + * Creates a new TrackedLocation instance which tracks a location about a craft's midpoint. + * @param craft The craft that's that tied to the location. + * @param location The absolute position to track. This location will be stored as a relative + * location to the craft's central hitbox. */ - public TrackedLocation(@NotNull MovecraftLocation origin, @NotNull MovecraftLocation location) { - this.origin = origin; - posX = location.getX() - origin.getX(); - posY = location.getY() - origin.getY(); - posZ = location.getZ() - origin.getZ(); + public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location) { + this.craft = craft; + MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); + offSet = new MovecraftLocation( + location.getX() - midPoint.getX(), + location.getY() - midPoint.getY(), + location.getZ() - midPoint.getZ() + ); } /** - * Moves the origin point of the tracked location - */ - public void translate(int dx, int dy, int dz) { - origin = new MovecraftLocation(origin.getX() + dx, origin.getY() + dy, origin.getZ() + dz); - } - - /** - * Rotates the stored location about the origin point location. + * Rotates the stored location about any point. * @param rotation A clockwise or counter-clockwise direction to rotate. + * @param pivot An absolute position at which to rotate the trackedLocation. */ - public void rotate(MovecraftRotation rotation) { - int newX; - int newZ; - if (rotation == MovecraftRotation.CLOCKWISE) { - newX = posZ + origin.getX(); - newZ = -posX + origin.getZ(); - } else if (rotation == MovecraftRotation.ANTICLOCKWISE) { - newX = -posZ + origin.getX(); - newZ = posX + origin.getZ(); - } else return; - - posX = newX; - posZ = newZ; + public void rotate(MovecraftRotation rotation, MovecraftLocation pivot) { + //This is the position vector relative to the tracked location to the pivot. + MovecraftLocation offSetToPivot = new MovecraftLocation( + getAbsoluteLocation().getX() - pivot.getX(), + getAbsoluteLocation().getY() - pivot.getY(), + getAbsoluteLocation().getZ() - pivot.getZ() + ); + //This is the position vector relative to the midpoint to the pivot. + MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); + MovecraftLocation midPointToPivot = new MovecraftLocation( + midPoint.getX() - pivot.getX(), + midPoint.getY() - pivot.getY(), + midPoint.getZ() - pivot.getZ() + ); + //Rotates both vectors + MovecraftLocation rotatedOffSetToPivot = MathUtils.rotateVec(rotation, offSetToPivot); + MovecraftLocation rotatedMidPointToPivot = MathUtils.rotateVec(rotation, midPointToPivot); + //Subtracts rotatedOffSetToPivot - rotatedMidPointToPivot to get the new offset to the midpoint. + offSet = new MovecraftLocation( + rotatedOffSetToPivot.getX() - rotatedMidPointToPivot.getX(), + rotatedOffSetToPivot.getY() - rotatedMidPointToPivot.getY(), + rotatedOffSetToPivot.getZ() - rotatedMidPointToPivot.getZ() + ); } /** * Gets the stored location. * @return Returns the location. */ - public MovecraftLocation getLocation() { - return new MovecraftLocation(posX + origin.getX(), posY + origin.getY(), posZ + origin.getZ()); + public MovecraftLocation getAbsoluteLocation() { + MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); + return new MovecraftLocation( + offSet.getX() + midPoint.getX(), + offSet.getY() + midPoint.getY(), + offSet.getZ() + midPoint.getZ() + ); } } diff --git a/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java b/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java index 0c69cd555..c40e9c0f3 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/craft/Craft.java @@ -33,9 +33,7 @@ import org.bukkit.World; import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Map; import java.util.Set; @@ -266,9 +264,5 @@ default void setLastDZ(int dZ){} void setTotalFuel (double fuel); - Map getTrackedLocations(); - - void addTrackedLocation(NamespacedKey key, MovecraftLocation location); - - void removeTrackedLocation(NamespacedKey key); + Map> getTrackedLocations(); } From a69c2cd1ca35897b68114763fcc76726f23f97fc Mon Sep 17 00:00:00 2001 From: goodroach Date: Sun, 31 Mar 2024 02:34:48 -1000 Subject: [PATCH 3/7] use built-in methods for vector manipulation --- .../movecraft/TrackedLocation.java | 51 ++++++------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java index 5908f0753..b08a00dcd 100644 --- a/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java +++ b/modules/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java @@ -17,53 +17,32 @@ public class TrackedLocation { public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location) { this.craft = craft; MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); - offSet = new MovecraftLocation( - location.getX() - midPoint.getX(), - location.getY() - midPoint.getY(), - location.getZ() - midPoint.getZ() - ); + offSet = location.subtract(midPoint); } /** - * Rotates the stored location about any point. + * Rotates the stored location. * @param rotation A clockwise or counter-clockwise direction to rotate. - * @param pivot An absolute position at which to rotate the trackedLocation. */ - public void rotate(MovecraftRotation rotation, MovecraftLocation pivot) { - //This is the position vector relative to the tracked location to the pivot. - MovecraftLocation offSetToPivot = new MovecraftLocation( - getAbsoluteLocation().getX() - pivot.getX(), - getAbsoluteLocation().getY() - pivot.getY(), - getAbsoluteLocation().getZ() - pivot.getZ() - ); - //This is the position vector relative to the midpoint to the pivot. + public void rotate(MovecraftRotation rotation) { MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); - MovecraftLocation midPointToPivot = new MovecraftLocation( - midPoint.getX() - pivot.getX(), - midPoint.getY() - pivot.getY(), - midPoint.getZ() - pivot.getZ() - ); - //Rotates both vectors - MovecraftLocation rotatedOffSetToPivot = MathUtils.rotateVec(rotation, offSetToPivot); - MovecraftLocation rotatedMidPointToPivot = MathUtils.rotateVec(rotation, midPointToPivot); - //Subtracts rotatedOffSetToPivot - rotatedMidPointToPivot to get the new offset to the midpoint. - offSet = new MovecraftLocation( - rotatedOffSetToPivot.getX() - rotatedMidPointToPivot.getX(), - rotatedOffSetToPivot.getY() - rotatedMidPointToPivot.getY(), - rotatedOffSetToPivot.getZ() - rotatedMidPointToPivot.getZ() - ); + offSet = MathUtils.rotateVec(rotation, getAbsoluteLocation().subtract(midPoint)); } /** - * Gets the stored location. - * @return Returns the location. + * Gets the stored absolute location. + * @return Returns the absolute location instead of a vector. */ public MovecraftLocation getAbsoluteLocation() { MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); - return new MovecraftLocation( - offSet.getX() + midPoint.getX(), - offSet.getY() + midPoint.getY(), - offSet.getZ() + midPoint.getZ() - ); + return offSet.add(midPoint); + } + + /** + * Gets the stored location as a position vector relative to the midpoint. + * @return Returns the absolute location instead of a vector. + */ + public MovecraftLocation getOffSet() { + return offSet; } } From 05dc0f8cb272be352324c0064f3e2d3295500e50 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Jul 2024 08:14:42 -0500 Subject: [PATCH 4/7] Fix merge --- .../main/java/net/countercraft/movecraft/craft/Craft.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/api/src/main/java/net/countercraft/movecraft/craft/Craft.java b/api/src/main/java/net/countercraft/movecraft/craft/Craft.java index 2be702f45..1e9e61555 100644 --- a/api/src/main/java/net/countercraft/movecraft/craft/Craft.java +++ b/api/src/main/java/net/countercraft/movecraft/craft/Craft.java @@ -40,12 +40,7 @@ import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.Collections; -import java.util.WeakHashMap; +import java.util.*; public interface Craft { CraftDataTagKey> CONTACTS = CraftDataTagContainer.tryRegisterTagKey(new NamespacedKey("movecraft", "contacts"), craft -> new ArrayList<>(0)); From 0ee61380cd0f974a5a94e3c6c9a8eafa89fe634b Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Jul 2024 08:24:48 -0500 Subject: [PATCH 5/7] Fix build --- .../java/net/countercraft/movecraft/TrackedLocation.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java b/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java index b08a00dcd..d61d74cab 100644 --- a/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java +++ b/api/src/main/java/net/countercraft/movecraft/TrackedLocation.java @@ -24,9 +24,8 @@ public TrackedLocation(@NotNull Craft craft, @NotNull MovecraftLocation location * Rotates the stored location. * @param rotation A clockwise or counter-clockwise direction to rotate. */ - public void rotate(MovecraftRotation rotation) { - MovecraftLocation midPoint = craft.getHitBox().getMidPoint(); - offSet = MathUtils.rotateVec(rotation, getAbsoluteLocation().subtract(midPoint)); + public void rotate(MovecraftRotation rotation, MovecraftLocation origin) { + offSet = MathUtils.rotateVec(rotation, getAbsoluteLocation().subtract(origin)); } /** From 964c3b71f01386c02dd79e87796b06a7625fa289 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Jul 2024 08:33:44 -0500 Subject: [PATCH 6/7] Process tracked locations on all parent crafts --- .../movecraft/async/rotation/RotationTask.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java index a542ea790..9cb10906a 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java @@ -27,6 +27,7 @@ import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.craft.CraftManager; import net.countercraft.movecraft.craft.SinkingCraft; +import net.countercraft.movecraft.craft.SubCraft; import net.countercraft.movecraft.craft.type.CraftType; import net.countercraft.movecraft.events.CraftRotateEvent; import net.countercraft.movecraft.events.CraftTeleportEntityEvent; @@ -178,11 +179,18 @@ protected void execute() { parentCraft.getFluidLocations().addAll(newFluidList); } - //Rotates the craft's tracked locations. - for (Set locations : craft.getTrackedLocations().values()) { - for (TrackedLocation location : locations) { - location.rotate(rotation, originPoint); + // Rotates the craft's tracked locations, then all parent craft's. + Craft temp = craft; + while (true) { + for (Set locations : craft.getTrackedLocations().values()) { + for (TrackedLocation location : locations) { + location.rotate(rotation, originPoint); + } } + if (!(temp instanceof SubCraft)) + break; + + temp = ((SubCraft) temp).getParent(); } updates.add(new CraftRotateCommand(getCraft(),originPoint, rotation)); From 84b4dd6936f98b618b717a1c529494f64ccae510 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Sun, 28 Jul 2024 09:50:36 -0500 Subject: [PATCH 7/7] Update RotationTask.java --- .../movecraft/async/rotation/RotationTask.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java index 9cb10906a..9e9453f11 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/rotation/RotationTask.java @@ -179,19 +179,15 @@ protected void execute() { parentCraft.getFluidLocations().addAll(newFluidList); } - // Rotates the craft's tracked locations, then all parent craft's. + // Rotates the craft's tracked locations, and all parent craft's. Craft temp = craft; - while (true) { + do { for (Set locations : craft.getTrackedLocations().values()) { for (TrackedLocation location : locations) { location.rotate(rotation, originPoint); } } - if (!(temp instanceof SubCraft)) - break; - - temp = ((SubCraft) temp).getParent(); - } + } while (temp instanceof SubCraft && (temp = ((SubCraft) temp).getParent()) != null); updates.add(new CraftRotateCommand(getCraft(),originPoint, rotation)); //rotate entities in the craft