Update to 1.20.1
This commit is contained in:
parent
0066b86d18
commit
f3b1ccbd3a
20 changed files with 200 additions and 166 deletions
|
@ -8,20 +8,18 @@ import net.minecraft.resources.ResourceLocation;
|
|||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class WorldPosition
|
||||
{
|
||||
|
||||
public class WorldPosition {
|
||||
|
||||
public Vector3 Position;
|
||||
public String Dimension;
|
||||
public String DimSafe;
|
||||
|
||||
public WorldPosition(CompoundTag tag, boolean pretty) throws InvalidDeserialization
|
||||
{
|
||||
if(pretty){
|
||||
public WorldPosition(CompoundTag tag, boolean pretty) throws InvalidDeserialization {
|
||||
if (pretty) {
|
||||
|
||||
Position = new Vector3(tag.getString("Position"));
|
||||
Dimension = tag.getString("Dimension");
|
||||
}else {
|
||||
} else {
|
||||
Position = new Vector3(tag.getCompound("pos"));
|
||||
Dimension = tag.getString("Dimension");
|
||||
}
|
||||
|
@ -30,64 +28,57 @@ public class WorldPosition
|
|||
|
||||
}
|
||||
|
||||
public WorldPosition(Vector3 pos, String dim)
|
||||
{
|
||||
Position=pos;
|
||||
Dimension=dim;
|
||||
public WorldPosition(Vector3 pos, String dim) {
|
||||
Position = pos;
|
||||
Dimension = dim;
|
||||
calcDimSafe();
|
||||
}
|
||||
|
||||
public WorldPosition(ServerPlayer player)
|
||||
{
|
||||
this(new Vector3(player.position()), player.getLevel());
|
||||
public WorldPosition(ServerPlayer player) {
|
||||
this(new Vector3(player.position()), player.serverLevel());
|
||||
}
|
||||
|
||||
public WorldPosition(Vector3 pos, ServerLevel lvl)
|
||||
{
|
||||
Position=pos;
|
||||
Dimension = 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();
|
||||
}
|
||||
|
||||
public void calcDimSafe()
|
||||
{
|
||||
public void calcDimSafe() {
|
||||
ServerLevel lvl = getActualDimension();
|
||||
DimSafe = lvl.dimension().location().getNamespace() + "-" + lvl.dimension().location().getPath();
|
||||
}
|
||||
public static String getDimSafe(ServerLevel lvl)
|
||||
{
|
||||
|
||||
public static String getDimSafe(ServerLevel 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(ServerLevel lvl)
|
||||
{
|
||||
public static String getDim(ServerLevel lvl) {
|
||||
return lvl.dimension().location().getNamespace() + ":" + lvl.dimension().location().getPath();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return NbtUtils.structureToSnbt(serialize());
|
||||
}
|
||||
|
||||
public CompoundTag serializePretty()
|
||||
{
|
||||
public CompoundTag serializePretty() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
|
||||
|
||||
tag.putString("Position", Position.toString());
|
||||
tag.putString("Dimension", Dimension);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
public CompoundTag serialize() {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("pos", Position.serialize());
|
||||
tag.putString("Dimension", Dimension);
|
||||
|
@ -95,46 +86,40 @@ public class WorldPosition
|
|||
return tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ServerLevel getActualDimension()
|
||||
{
|
||||
|
||||
public ServerLevel getActualDimension() {
|
||||
|
||||
String dim = Dimension;
|
||||
String[] dims = dim.split(":");
|
||||
|
||||
ResourceLocation rl = new ResourceLocation(dims[0], dims[1]);
|
||||
ServerLevel dimL = null;
|
||||
ServerLevel dimL = null;
|
||||
for (ServerLevel lServerLevel : LibZontreck.THE_SERVER.getAllLevels()) {
|
||||
ResourceLocation XL = lServerLevel.dimension().location();
|
||||
|
||||
if(XL.getNamespace().equals(rl.getNamespace())){
|
||||
if(XL.getPath().equals(rl.getPath())){
|
||||
if (XL.getNamespace().equals(rl.getNamespace())) {
|
||||
if (XL.getPath().equals(rl.getPath())) {
|
||||
dimL = lServerLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dimL == null)
|
||||
{
|
||||
LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : "+Dimension);
|
||||
if (dimL == null) {
|
||||
LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : " + Dimension);
|
||||
return null;
|
||||
}
|
||||
|
||||
return dimL;
|
||||
}
|
||||
|
||||
|
||||
public boolean same(WorldPosition other)
|
||||
{
|
||||
if(Position.same(other.Position) && Dimension == other.Dimension)return true;
|
||||
else return false;
|
||||
|
||||
public boolean same(WorldPosition other) {
|
||||
return Position.same(other.Position) && Dimension == other.Dimension;
|
||||
}
|
||||
|
||||
public ChunkPos getChunkPos()
|
||||
{
|
||||
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()), getActualDimension());
|
||||
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;
|
||||
|
|
Reference in a new issue