diff --git a/modules/MakeItBuild.md b/modules/MakeItBuild.md new file mode 100644 index 000000000..d1c90db26 --- /dev/null +++ b/modules/MakeItBuild.md @@ -0,0 +1 @@ +Make it Build! 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..1abf883ec 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 @@ -15,6 +15,10 @@ import net.countercraft.movecraft.processing.WorldManager; import net.countercraft.movecraft.util.Counter; import net.countercraft.movecraft.util.Tags; + +import net.countercraft.movecraft.util.CollectionUtils; +import net.countercraft.movecraft.util.MathUtils; + import net.countercraft.movecraft.util.TimingData; import net.countercraft.movecraft.util.hitboxes.HitBox; import net.countercraft.movecraft.util.hitboxes.MutableHitBox; @@ -30,6 +34,7 @@ import org.bukkit.block.Sign; import org.bukkit.block.data.BlockData; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.EnumSet; @@ -115,6 +120,147 @@ public CraftType getType() { return type; } + @Override + public void setDataTag(String key, Object data) { + this.craftTags.put(key, data); + } + @Override + @Nullable + public Object removeDataTag(String key) { + Object tag = this.craftTags.getOrDefault(key, null); + this.craftTags.remove(key); + return tag; + } + @Override + @Nullable + public Object getDataTag(String key) { + return this.craftTags.getOrDefault(key, null); + } + @Override + public Collection getAllTagValues() { + return this.craftTags.values(); + } + @Override + public boolean hasDataKey(String key) { + return this.craftTags.containsKey(key); + } + @Override + public boolean hasDataValue(Object value) { + return this.craftTags.containsValue(value); + } + + @Override + public HitBox translateBox(HitBox box, MovecraftLocation vec) { + SetHitBox newBox = new SetHitBox(); + for(MovecraftLocation oldLoc : box) { + MovecraftLocation newLoc = oldLoc.translate(vec.getX(),vec.getY(),vec.getZ()); + newBox.add(newLoc); + } + return newBox; + } + @Override + public HitBox rotateBox(HitBox box, MovecraftLocation axis, MovecraftRotation rotation) { + SetHitBox newBox = new SetHitBox(); + for(MovecraftLocation oldLoc : box){ + MovecraftLocation newLoc = MathUtils.rotateVec(rotation,oldLoc.subtract(axis)).add(axis); + newBox.add(newLoc); + } + return newBox; + } + + @Override + public boolean isTracking(@NotNull Object tracked) { + boolean found = false; + if (tracked instanceof MovecraftLocation || tracked instanceof HitBox) { + for (Object key : this.trackedLocations.keySet()) { + if (this.trackedLocations.get(key).contains(tracked)) { + found = true; + return found; + } + } + } + return found; + } + @Override + public void setTrackedLocs(@NotNull Collection tracked, @NotNull Object key) { + if (this.trackedLocations.containsKey(key)) { + Set mlocs = new HashSet<>(); + mlocs.addAll(this.trackedLocations.get(key)); + for (Object o : tracked) { + if (o instanceof MovecraftLocation || o instanceof HitBox) { + continue; + } else { + return; + } + } + this.trackedLocations.put(key, tracked); + } else { + for (Object o : tracked) { + if (o instanceof MovecraftLocation || o instanceof HitBox) { + continue; + } else { + return; + } + } + this.trackedLocations.put(key, tracked); + } + } + @Override + public void addTrackedLoc(@NotNull Object tracked, @NotNull Object key) { + if (tracked instanceof MovecraftLocation || tracked instanceof HitBox) { + if (this.trackedLocations.containsKey(key)) { + Set mlocs = new HashSet<>(this.trackedLocations.get(key)); + mlocs.add(tracked); + this.trackedLocations.put(key, mlocs); + } else { + Set mlocs = new HashSet<>(); + mlocs.add(tracked); + this.trackedLocations.put(key, mlocs); + } + } + } + @Override + public void removeTrackedLoc(@NotNull Object tracked, @NotNull Object key) { + if (tracked instanceof MovecraftLocation || tracked instanceof HitBox) { + if (this.trackedLocations.containsKey(key)) { + Set mlocs = new HashSet<>(this.trackedLocations.get(key)); + mlocs.remove(tracked); + this.trackedLocations.put(key, mlocs); + } + } + } + @Override + public Set getAllTrackedLocation() { + Set mlocs = new HashSet<>(); + for (Object key : this.trackedLocations.keySet()) { + for (Object o : this.trackedLocations.get(key)) { + if (o instanceof MovecraftLocation) { + mlocs.add(o); + } + if (o instanceof SetHitBox) { + mlocs.add(((SetHitBox)o).asSet()); + } + } + } + return mlocs; + } + @Override + @Nullable + public Set getTrackedLocs(@NotNull Object key) { + if (this.trackedLocations.get(key) == null) + return null; + Set mlocs = new HashSet<>(getHitBox().size()*8); + for (Object o : this.trackedLocations.get(key)) { + if (o instanceof MovecraftLocation || o instanceof HitBox) { + if (o instanceof MovecraftLocation) + mlocs.add((MovecraftLocation)o); + if (o instanceof HitBox) + mlocs.addAll(((HitBox)o).asSet()); + } + } + return mlocs; + } + @NotNull public MovecraftWorld getMovecraftWorld() { return CachedMovecraftWorld.of(w); diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftRotateCommand.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftRotateCommand.java index 45b6c2cc8..8bb0c5d18 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftRotateCommand.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftRotateCommand.java @@ -69,6 +69,27 @@ public void doUpdate() { CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.EMPTY, false); return; } + if (craft.trackedLocations != null) { + ArrayList clone = new ArrayList<>(); + for (Object key : craft.trackedLocations.keySet()) { + ArrayList mlocs = new ArrayList<>(craft.getTrackedLocs(key)); + for (Object tracked : mlocs) { + if (tracked != null) { + if (tracked instanceof MovecraftLocation) { + MovecraftLocation newTracked = MathUtils.rotateVec(rotation,((MovecraftLocation)tracked).subtract(originLocation)).add(originLocation); + clone.add(newTracked); + } + if (tracked instanceof HitBox) { + HitBox newBox = (SetHitBox)(craft).rotateBox(((HitBox)tracked), originLocation, rotation); + clone.add(newBox); + } + } + } + if (!clone.isEmpty() || clone != null) { + (craft).setTrackedLocs(clone,key); + } + } + } long time = System.nanoTime(); final Set passthroughBlocks = new HashSet<>(craft.getType().getMaterialSetProperty(CraftType.PASSTHROUGH_BLOCKS)); if (craft instanceof SinkingCraft) { diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftTranslateCommand.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftTranslateCommand.java index fe03a2a28..3a5def9ba 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftTranslateCommand.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/CraftTranslateCommand.java @@ -75,6 +75,28 @@ public void doUpdate() { CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.EMPTY, false); return; } + + if (craft.trackedLocations != null) { + for (Object key : craft.trackedLocations.keySet()) { + ArrayList mlocs = new ArrayList<>(craft.trackedLocations.get(key)); + Set clone = new HashSet<>(); + for (Object tracked : mlocs) { + if (tracked != null) { + if (tracked instanceof MovecraftLocation) { + MovecraftLocation newTracked = ((MovecraftLocation)tracked).translate(displacement.getX(),displacement.getY(),displacement.getZ()); + clone.add(newTracked); + } + if (tracked instanceof HitBox) { + HitBox newBox = (SetHitBox)(craft.translateBox(((SetHitBox)tracked), displacement)); + clone.add(newBox); + } + } + } + if (!clone.isEmpty() || clone != null) { + (craft).setTrackedLocs(clone,key); + } + } + } long time = System.nanoTime(); World oldWorld = craft.getWorld(); final Set passthroughBlocks = new HashSet<>( 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..4739c45d0 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 @@ -35,6 +35,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; +import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -45,7 +47,6 @@ public interface Craft { @Deprecated void setProcessing(boolean processing); - /** * Gets a HitBox representing the current locations that this craft controls * @@ -58,7 +59,6 @@ public interface Craft { * Sets the HitBox representing the current locations that this craft controls */ void setHitBox(@NotNull HitBox hitBox); - /** * Gets the CraftType used to determine the Craft's behaviours * @@ -67,6 +67,94 @@ public interface Craft { @NotNull CraftType getType(); + + Map> trackedLocations = new HashMap<>(); + + Map craftTags = new HashMap<>(); + + /** + * Attaches a Key-Value Pair to a Craft Object. + */ + void setDataTag(@NotNull String key, @Nullable Object data); + + /** + * Gets the Value of and then Removes the Key, if Present (Otherwise Returns Null). + */ + @Nullable + Object removeDataTag(String key); + + /** + * Gets a Tag Value from a Keys. + */ + @Nullable + Object getDataTag(String key); + + /** + * Gets all Tag Values from all Keys. + */ + @NotNull + Collection getAllTagValues(); + + /** + * Checks if the Craft has a certain Key out of all Keys + */ + @NotNull + boolean hasDataKey(String key); + + /** + * Checks if the Craft has a certain Value from all Keys + */ + @NotNull + boolean hasDataValue(Object value); + + /** + * Translates the given HitBox by a MovecraftLocation (Which is Treated as a Vector) + */ + @NotNull + HitBox translateBox(HitBox box, MovecraftLocation vec); + + /** + * Rotates the given HitBox around an Axis by a MovecraftRotation + */ + @NotNull + HitBox rotateBox(HitBox box, MovecraftLocation axis, MovecraftRotation rotation); + + /** + * Checks if an Object (MovecraftLocation / HitBox) is currently being Tracked. + */ + @NotNull + boolean isTracking(@NotNull Object tracked); + + /** + * Replaces/Updates a Key of Tracked MovecraftLocation or HitBox + */ + void setTrackedLocs(@NotNull Collection tracked, @NotNull Object key); + /** + * Adds a Tracked MovecraftLocation or HitBox to a Key + */ + void addTrackedLoc(@NotNull Object tracked, @NotNull Object key); + /** + * Removes a Tracked MovecraftLocation or HitBox from a Key + */ + void removeTrackedLoc(@NotNull Object tracked, @NotNull Object key); + /** + * Gets all Tracked MovecraftLocations (Including from Tracked HitBoxes) from all Keys + */ + Set getAllTrackedLocation(); + + /** + * Gets all Tracked MovecraftLocations (Including from Tracked HitBoxes) or HitBox from a particular key + */ + @Nullable + Set getTrackedLocs(@NotNull Object key); + + /** + * Gets a HitBox representing the current locations that this craft controls + * + * @return the crafts current HitBox + */ + + @Deprecated(forRemoval = true) @NotNull default World getW(){ return this.getWorld();