From bdcb708195db35a81307e33e4150b4b315df02fb Mon Sep 17 00:00:00 2001 From: themode Date: Sat, 12 Dec 2020 23:15:33 +0100 Subject: [PATCH] Fix CompassMeta --- build.gradle | 2 +- .../server/item/metadata/CompassMeta.java | 60 ++++++++----------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index 58bb43f0d..3dc6386f3 100644 --- a/build.gradle +++ b/build.gradle @@ -113,7 +113,7 @@ dependencies { api 'io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.2.Final:linux-x86_64' // https://mvnrepository.com/artifact/it.unimi.dsi/fastutil - api 'it.unimi.dsi:fastutil:8.4.3' + api 'it.unimi.dsi:fastutil:8.4.4' // https://mvnrepository.com/artifact/com.google.code.gson/gson api 'com.google.code.gson:gson:2.8.6' diff --git a/src/main/java/net/minestom/server/item/metadata/CompassMeta.java b/src/main/java/net/minestom/server/item/metadata/CompassMeta.java index 1c4d83e0d..8a0e007a9 100644 --- a/src/main/java/net/minestom/server/item/metadata/CompassMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/CompassMeta.java @@ -1,13 +1,18 @@ package net.minestom.server.item.metadata; +import net.minestom.server.utils.Position; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jglrxavpok.hephaistos.nbt.NBTCompound; +import java.util.Objects; + public class CompassMeta extends ItemMeta { private boolean lodestoneTracked; private String lodestoneDimension; - private int x, y, z; + + private Position lodestonePosition; public boolean isLodestoneTracked() { return lodestoneTracked; @@ -17,36 +22,22 @@ public class CompassMeta extends ItemMeta { this.lodestoneTracked = lodestoneTracked; } + @Nullable public String getLodestoneDimension() { return lodestoneDimension; } - public void setLodestoneDimension(String lodestoneDimension) { + public void setLodestoneDimension(@Nullable String lodestoneDimension) { this.lodestoneDimension = lodestoneDimension; } - public int getX() { - return x; + @Nullable + public Position getLodestonePosition() { + return lodestonePosition; } - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public int getZ() { - return z; - } - - public void setZ(int z) { - this.z = z; + public void setLodestonePosition(@Nullable Position lodestonePosition) { + this.lodestonePosition = lodestonePosition; } @Override @@ -60,24 +51,25 @@ public class CompassMeta extends ItemMeta { return false; CompassMeta compassMeta = (CompassMeta) itemMeta; return (compassMeta.lodestoneTracked == lodestoneTracked) && - (compassMeta.lodestoneDimension.equals(lodestoneDimension)) && - (compassMeta.x == x && compassMeta.y == y && compassMeta.z == z); + (Objects.equals(compassMeta.lodestoneDimension, lodestoneDimension)) && + (Objects.equals(compassMeta.lodestonePosition, lodestonePosition)); } @Override public void read(@NotNull NBTCompound compound) { if (compound.containsKey("LodestoneTracked")) { this.lodestoneTracked = compound.getByte("LodestoneTracked") == 1; - // TODO get boolean } if (compound.containsKey("LodestoneDimension")) { this.lodestoneDimension = compound.getString("LodestoneDimension"); } if (compound.containsKey("LodestonePos")) { final NBTCompound posCompound = compound.getCompound("LodestonePos"); - this.x = posCompound.getInt("X"); - this.y = posCompound.getInt("Y"); - this.z = posCompound.getInt("Z"); + final int x = posCompound.getInt("X"); + final int y = posCompound.getInt("Y"); + final int z = posCompound.getInt("Z"); + + this.lodestonePosition = new Position(x, y, z); } } @@ -88,11 +80,11 @@ public class CompassMeta extends ItemMeta { compound.setString("LodestoneDimension", lodestoneDimension); } - { + if (lodestonePosition != null) { NBTCompound posCompound = new NBTCompound(); - posCompound.setInt("X", x); - posCompound.setInt("Y", y); - posCompound.setInt("Z", z); + posCompound.setInt("X", (int) lodestonePosition.getX()); + posCompound.setInt("Y", (int) lodestonePosition.getY()); + posCompound.setInt("Z", (int) lodestonePosition.getZ()); compound.set("LodestonePos", posCompound); } } @@ -103,9 +95,7 @@ public class CompassMeta extends ItemMeta { CompassMeta compassMeta = (CompassMeta) super.clone(); compassMeta.lodestoneTracked = lodestoneTracked; compassMeta.lodestoneDimension = lodestoneDimension; - compassMeta.x = x; - compassMeta.y = y; - compassMeta.z = z; + compassMeta.lodestonePosition = lodestonePosition != null ? lodestonePosition.clone() : null; return compassMeta; }