From 4eee51709c76ffe3805df51fa955c3037efa817b Mon Sep 17 00:00:00 2001 From: Aria Date: Tue, 14 Feb 2023 10:47:03 -0700 Subject: [PATCH] Add a middle chunk position to the chunk pos interface --- gradle.properties | 2 +- .../libzontreck/vectors/ChunkPos.java | 27 ++++++++++++++++--- .../zontreck/libzontreck/vectors/Points.java | 20 +++++++------- .../libzontreck/vectors/WorldPosition.java | 1 + src/main/resources/META-INF/mods.toml | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8287e57..011c9b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.daemon=false mc_version=1.19.2 forge_version=43.2.3 -myversion=1.0.4.2 +myversion=1.0.4.3 parchment_version=2022.11.27 \ No newline at end of file diff --git a/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java b/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java index 5b47e70..e504587 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java @@ -1,23 +1,42 @@ package dev.zontreck.libzontreck.vectors; +import net.minecraft.nbt.CompoundTag; + public class ChunkPos { public boolean isSubArea; - public Points subclaim; - + public Points points; + public Vector2 centerPoints; public ChunkPos(Vector3 point1, Vector3 point2) { isSubArea=true; - subclaim = new Points(point1, point2); + points = new Points(point1, point2); + } + + public ChunkPos(CompoundTag tag) + { + isSubArea = tag.getBoolean("subarea"); + points = new Points(tag.getCompound("points")); + centerPoints = new Vector2(tag.getCompound("center")); } public boolean isWithin(Vector3 point) { - return point.inside(subclaim.Point1, subclaim.Point2); + return point.inside(points.Min, points.Max); } public static ChunkPos getChunkPos(WorldPosition pos) { return pos.getChunkPos(); } + + public CompoundTag serialize() + { + CompoundTag tag = new CompoundTag(); + tag.putBoolean("subarea", isSubArea); + tag.put("points", points.serialize()); + tag.put("center", centerPoints.serialize()); + + return tag; + } } diff --git a/src/main/java/dev/zontreck/libzontreck/vectors/Points.java b/src/main/java/dev/zontreck/libzontreck/vectors/Points.java index e43fd94..147d26a 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/Points.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/Points.java @@ -3,19 +3,19 @@ package dev.zontreck.libzontreck.vectors; import net.minecraft.nbt.CompoundTag; public class Points { - public Vector3 Point1 = Vector3.ZERO; - public Vector3 Point2 = Vector3.ZERO; + public Vector3 Min = Vector3.ZERO; + public Vector3 Max = Vector3.ZERO; public Points(Vector3 min, Vector3 max) { if(min.less(max)) { - Point1=min; - Point2=max; + Min=min; + Max=max; }else{ - Point1=max; - Point2=min; + Min=max; + Max=min; } } @@ -25,14 +25,14 @@ public class Points { public CompoundTag serialize(){ CompoundTag tag = new CompoundTag(); - tag.put("min", Point1.serialize()); - tag.put("max", Point2.serialize()); + tag.put("min", Min.serialize()); + tag.put("max", Max.serialize()); return tag; } public void deserialize(CompoundTag tag) { - Point1 = new Vector3(tag.getCompound("min")); - Point2 = new Vector3(tag.getCompound("max")); + Min = new Vector3(tag.getCompound("min")); + Max = new Vector3(tag.getCompound("max")); } } diff --git a/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java b/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java index 5fe5764..88ee45f 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java @@ -119,6 +119,7 @@ public class WorldPosition net.minecraft.world.level.ChunkPos mcChunk = getActualDimension().getChunkAt(Position.asBlockPos()).getPos(); ChunkPos pos = new ChunkPos(new Vector3(mcChunk.getMinBlockX(),-70,mcChunk.getMinBlockZ()), new Vector3(mcChunk.getMaxBlockX(), 400, mcChunk.getMaxBlockZ())); pos.isSubArea=false; + pos.centerPoints = new Vector2(mcChunk.getMiddleBlockX(), mcChunk.getMiddleBlockZ()); return pos; } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 3ab0960..cd6f2b9 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="libzontreck" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.0.4.2" #mandatory +version="1.0.4.3" #mandatory # A display name for the mod displayName="LibZontreck" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/