From e711ba6a2e4e8fd8b5dbb579fe3f8b790d758d87 Mon Sep 17 00:00:00 2001 From: Aria Date: Wed, 22 Feb 2023 20:19:26 -0700 Subject: [PATCH] Bugfix: Rollback clientlevel support --- gradle.properties | 2 +- .../libzontreck/vectors/ChunkPos.java | 3 +- .../zontreck/libzontreck/vectors/Points.java | 4 +- .../libzontreck/vectors/WorldPosition.java | 103 ++++-------------- src/main/resources/META-INF/mods.toml | 2 +- 5 files changed, 27 insertions(+), 87 deletions(-) diff --git a/gradle.properties b/gradle.properties index c280e3d..d249812 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.daemon=false mc_version=1.18.2 forge_version=40.2.1 -myversion=1.0.4.10 +myversion=1.0.4.11 parchment_version=2022.11.06 \ 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 9c5540c..219386a 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/ChunkPos.java @@ -1,6 +1,7 @@ package dev.zontreck.libzontreck.vectors; import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; public class ChunkPos { @@ -8,7 +9,7 @@ public class ChunkPos { public Vector2 centerPoints; public String dim; - public ChunkPos(Vector3 point1, Vector3 point2, Level lvl) + public ChunkPos(Vector3 point1, Vector3 point2, ServerLevel lvl) { points = new Points(point1, point2, lvl); dim = WorldPosition.getDim(lvl); diff --git a/src/main/java/dev/zontreck/libzontreck/vectors/Points.java b/src/main/java/dev/zontreck/libzontreck/vectors/Points.java index 1b027a3..fdb0cf9 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/Points.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/Points.java @@ -1,7 +1,7 @@ package dev.zontreck.libzontreck.vectors; import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.level.Level; +import net.minecraft.server.level.ServerLevel; /** * Two points within the same dimension @@ -17,7 +17,7 @@ public class Points { * @param max * @param lvl */ - public Points(Vector3 min, Vector3 max, Level lvl) + public Points(Vector3 min, Vector3 max, ServerLevel lvl) { dimension = WorldPosition.getDimSafe(lvl); if(min.less(max)) diff --git a/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java b/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java index 7918855..0216d29 100644 --- a/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java +++ b/src/main/java/dev/zontreck/libzontreck/vectors/WorldPosition.java @@ -2,19 +2,12 @@ package dev.zontreck.libzontreck.vectors; import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.exceptions.InvalidDeserialization; -import dev.zontreck.libzontreck.exceptions.InvalidSideException; -import net.minecraft.client.Minecraft; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -/** - * Stores a position relative to a dimension - */ public class WorldPosition { @@ -49,33 +42,19 @@ public class WorldPosition this(new Vector3(player.position()), player.getLevel()); } - public WorldPosition(Player player) - { - this(new Vector3(player.position()), player.getLevel()); - } - - public WorldPosition(Vector3 pos, Level lvl) - { - this(pos, lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath()); - } - public WorldPosition(Vector3 pos, ServerLevel lvl) { - this(pos, lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath()); + Position=pos; + Dimension = lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath(); + calcDimSafe(); } public void calcDimSafe() { - try{ - - Level lvl = getActualDimension(); - DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath(); - }catch(InvalidSideException ex) - { - DimSafe=""; - } + ServerLevel lvl = getActualDimension(); + DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath(); } - public static String getDimSafe(Level lvl) + public static String getDimSafe(ServerLevel lvl) { return lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath(); } @@ -85,21 +64,18 @@ public class WorldPosition * @param lvl * @return dimension string */ - public static String getDim(Level lvl) + public static String getDim(ServerLevel lvl) { return lvl.dimension().location().getNamespace() + ":" + lvl.dimension().location().getPath(); } + @Override public String toString() { return NbtUtils.structureToSnbt(serialize()); } - /** - * Stores the position as a string instead of as a compound tag. Uses more memory overall - * @return - */ public CompoundTag serializePretty() { CompoundTag tag = new CompoundTag(); @@ -110,10 +86,6 @@ public class WorldPosition return tag; } - /** - * Serializes the compound tag version of this position - * @return - */ public CompoundTag serialize() { CompoundTag tag = new CompoundTag(); @@ -125,41 +97,24 @@ public class WorldPosition - /** - * You must run this on the Server unless you know for a fact that the position you are requesting the dimension for is the same one the client is currently in. Otherwise you must handle the Exception properly. - * @return The level that this worldpos stores - * @throws InvalidSideException - */ - public Level getActualDimension() throws InvalidSideException + public ServerLevel getActualDimension() { String dim = Dimension; String[] dims = dim.split(":"); ResourceLocation rl = new ResourceLocation(dims[0], dims[1]); - Level dimL = null; - - if(Minecraft.getInstance()==null) - { + ServerLevel dimL = null; + for (ServerLevel lServerLevel : LibZontreck.THE_SERVER.getAllLevels()) { + ResourceLocation XL = lServerLevel.dimension().location(); - for (Level lLevel : LibZontreck.THE_SERVER.getAllLevels()) { - ResourceLocation XL = lLevel.dimension().location(); - - if(XL.getNamespace().equals(rl.getNamespace())){ - if(XL.getPath().equals(rl.getPath())){ - dimL = lLevel; - } + if(XL.getNamespace().equals(rl.getNamespace())){ + if(XL.getPath().equals(rl.getPath())){ + dimL = lServerLevel; } } - }else { - if(getDim(Minecraft.getInstance().level) == Dimension) - { - return Minecraft.getInstance().level; - }else throw new InvalidSideException("This operation must be run on the server as the client is not in the dimension you requested"); - } - if(dimL == null) { LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : "+Dimension); @@ -169,35 +124,19 @@ public class WorldPosition return dimL; } - /** - * Returns true if the other world position is identical - * @param other - * @return - */ + public boolean same(WorldPosition other) { if(Position.same(other.Position) && Dimension == other.Dimension)return true; else return false; } - /** - * Gets the LibZontreck ChunkPosition - * @return ChunkPos of the chunk mentioned by this worldposition, or null in the event that we are on the client and the dimension is not the same one we are inside. - * @see WorldPosition#getActualDimension() - */ public ChunkPos getChunkPos() { - try - { - Level lvl = getActualDimension(); - net.minecraft.world.level.ChunkPos mcChunk = lvl.getChunkAt(Position.asBlockPos()).getPos(); - ChunkPos pos = new ChunkPos(new Vector3(mcChunk.getMinBlockX(),-70,mcChunk.getMinBlockZ()), new Vector3(mcChunk.getMaxBlockX(), 400, mcChunk.getMaxBlockZ()), lvl); - pos.centerPoints = new Vector2(mcChunk.getMiddleBlockX(), mcChunk.getMiddleBlockZ()); - - return pos; - }catch(InvalidSideException ex) - { - return null; - } + 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()), getActualDimension()); + 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 108d7f3..10dc1ae 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.10" #mandatory +version="1.0.4.11" #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/