Publish changes to Library API
This commit is contained in:
parent
b01d45f9ab
commit
7e5c273f4d
6 changed files with 134 additions and 30 deletions
|
@ -5,5 +5,5 @@ org.gradle.daemon=false
|
|||
|
||||
mc_version=1.19.2
|
||||
forge_version=43.2.3
|
||||
myversion=1.0.4.4
|
||||
myversion=1.0.4.5
|
||||
parchment_version=2022.11.27
|
|
@ -0,0 +1,12 @@
|
|||
package dev.zontreck.libzontreck.exceptions;
|
||||
|
||||
/**
|
||||
* Thrown when requesting a world position's level on the client when in the wrong dimension.
|
||||
* @see WorldPosition
|
||||
*/
|
||||
public class InvalidSideException extends Exception
|
||||
{
|
||||
public InvalidSideException(String msg){
|
||||
super(msg);
|
||||
}
|
||||
}
|
|
@ -1,21 +1,21 @@
|
|||
package dev.zontreck.libzontreck.vectors;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class ChunkPos {
|
||||
public boolean isSubArea;
|
||||
public Points points;
|
||||
public Vector2 centerPoints;
|
||||
public String dim;
|
||||
|
||||
public ChunkPos(Vector3 point1, Vector3 point2)
|
||||
public ChunkPos(Vector3 point1, Vector3 point2, Level lvl)
|
||||
{
|
||||
isSubArea=true;
|
||||
points = new Points(point1, point2);
|
||||
points = new Points(point1, point2, lvl);
|
||||
dim = WorldPosition.getDim(lvl);
|
||||
}
|
||||
|
||||
public ChunkPos(CompoundTag tag)
|
||||
{
|
||||
isSubArea = tag.getBoolean("subarea");
|
||||
points = new Points(tag.getCompound("points"));
|
||||
centerPoints = new Vector2(tag.getCompound("center"));
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public class ChunkPos {
|
|||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putBoolean("subarea", isSubArea);
|
||||
tag.put("points", points.serialize());
|
||||
tag.put("center", centerPoints.serialize());
|
||||
tag.putString("dim", dim);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,25 @@
|
|||
package dev.zontreck.libzontreck.vectors;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Two points within the same dimension
|
||||
*/
|
||||
public class Points {
|
||||
public Vector3 Min = Vector3.ZERO;
|
||||
public Vector3 Max = Vector3.ZERO;
|
||||
public String dimension = "";
|
||||
|
||||
|
||||
public Points(Vector3 min, Vector3 max)
|
||||
/**
|
||||
* Creates a new set of points
|
||||
* @param min
|
||||
* @param max
|
||||
* @param lvl
|
||||
*/
|
||||
public Points(Vector3 min, Vector3 max, Level lvl)
|
||||
{
|
||||
dimension = WorldPosition.getDimSafe(lvl);
|
||||
if(min.less(max))
|
||||
{
|
||||
Min=min;
|
||||
|
@ -19,6 +30,10 @@ public class Points {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a points compound tag
|
||||
* @param tag
|
||||
*/
|
||||
public Points(CompoundTag tag){
|
||||
deserialize(tag);
|
||||
}
|
||||
|
@ -27,6 +42,7 @@ public class Points {
|
|||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("min", Min.serialize());
|
||||
tag.put("max", Max.serialize());
|
||||
tag.putString("dim", dimension);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
@ -34,5 +50,6 @@ public class Points {
|
|||
{
|
||||
Min = new Vector3(tag.getCompound("min"));
|
||||
Max = new Vector3(tag.getCompound("max"));
|
||||
dimension = tag.getString("dim");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
package dev.zontreck.libzontreck.vectors;
|
||||
|
||||
import com.mojang.authlib.yggdrasil.response.UserAttributesResponse.ProfanityFilterPreferences;
|
||||
|
||||
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.server.network.FilteredText;
|
||||
import net.minecraft.util.datafix.fixes.FilteredSignsFix;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Stores a position relative to a dimension
|
||||
*/
|
||||
public class WorldPosition
|
||||
{
|
||||
|
||||
|
@ -42,29 +53,57 @@ 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)
|
||||
{
|
||||
Position=pos;
|
||||
Dimension = lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath();
|
||||
calcDimSafe();
|
||||
this(pos, lvl.dimension().location().getNamespace() + ":"+lvl.dimension().location().getPath());
|
||||
}
|
||||
|
||||
public void calcDimSafe()
|
||||
{
|
||||
ServerLevel lvl = getActualDimension();
|
||||
try{
|
||||
|
||||
Level lvl = getActualDimension();
|
||||
DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath();
|
||||
}catch(InvalidSideException ex)
|
||||
{
|
||||
DimSafe="";
|
||||
}
|
||||
public static String getDimSafe(ServerLevel lvl)
|
||||
}
|
||||
public static String getDimSafe(Level lvl)
|
||||
{
|
||||
return lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives you the dimension string modid:dimension
|
||||
* @param lvl
|
||||
* @return dimension string
|
||||
*/
|
||||
public static String getDim(Level 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();
|
||||
|
@ -75,6 +114,10 @@ public class WorldPosition
|
|||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the compound tag version of this position
|
||||
* @return
|
||||
*/
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
|
@ -86,23 +129,40 @@ public class WorldPosition
|
|||
|
||||
|
||||
|
||||
public ServerLevel getActualDimension()
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
String dim = Dimension;
|
||||
String[] dims = dim.split(":");
|
||||
|
||||
ResourceLocation rl = new ResourceLocation(dims[0], dims[1]);
|
||||
ServerLevel dimL = null;
|
||||
for (ServerLevel lServerLevel : LibZontreck.THE_SERVER.getAllLevels()) {
|
||||
ResourceLocation XL = lServerLevel.dimension().location();
|
||||
Level dimL = null;
|
||||
|
||||
if(Minecraft.getInstance()==null)
|
||||
{
|
||||
|
||||
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 = lServerLevel;
|
||||
dimL = lLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}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)
|
||||
{
|
||||
|
@ -113,20 +173,35 @@ 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()
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.4" #mandatory
|
||||
version="1.0.4.5" #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/
|
||||
|
|
Reference in a new issue