mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
Add a method to reset Lodestone compasses back to normal ones (#11308)
This commit is contained in:
parent
2fa1146af5
commit
900192b490
3 changed files with 245 additions and 10 deletions
|
@ -40,6 +40,46 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
ItemType.Typed<ItemMeta> TOTEM_OF_UNDYING = getItemType("totem_of_undying");
|
||||
ItemType.Typed<ItemMeta> SHULKER_SHELL = getItemType("shulker_shell");
|
||||
ItemType.Typed<ItemMeta> IRON_NUGGET = getItemType("iron_nugget");
|
||||
diff --git a/src/main/java/org/bukkit/inventory/meta/CompassMeta.java b/src/main/java/org/bukkit/inventory/meta/CompassMeta.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/CompassMeta.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/meta/CompassMeta.java
|
||||
@@ -0,0 +0,0 @@ public interface CompassMeta extends ItemMeta {
|
||||
/**
|
||||
* Sets the location this lodestone compass will point to.
|
||||
*
|
||||
- * @param lodestone new location or null to clear
|
||||
+ * @param lodestone new location or null to clear the targeted location
|
||||
+ * @see #clearLodestone() to reset the compass to a normal compass
|
||||
*/
|
||||
void setLodestone(@Nullable Location lodestone);
|
||||
|
||||
@@ -0,0 +0,0 @@ public interface CompassMeta extends ItemMeta {
|
||||
* location.
|
||||
*
|
||||
* @param tracked new tracked status
|
||||
+ * @see #clearLodestone() to reset the compass to a normal compass
|
||||
*/
|
||||
void setLodestoneTracked(boolean tracked);
|
||||
|
||||
+ // Paper start - Add more lodestone compass methods
|
||||
+ /**
|
||||
+ * Checks if this compass is considered a lodestone compass.
|
||||
+ * @see #hasLodestone() to check if a position is being tracked
|
||||
+ * @see #isLodestoneTracked() to check if it verifies the position is a lodestone
|
||||
+ */
|
||||
+ boolean isLodestoneCompass();
|
||||
+
|
||||
+ /**
|
||||
+ * Reset this compass to a normal compass, removing any tracked
|
||||
+ * location.
|
||||
+ */
|
||||
+ void clearLodestone();
|
||||
+ // Paper end - Add more lodestone compass methods
|
||||
+
|
||||
@Override
|
||||
CompassMeta clone();
|
||||
}
|
||||
diff --git a/src/main/java/org/bukkit/inventory/meta/Damageable.java b/src/main/java/org/bukkit/inventory/meta/Damageable.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/Damageable.java
|
||||
|
|
|
@ -600,38 +600,233 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
private int lodestoneX;
|
||||
private int lodestoneY;
|
||||
private int lodestoneZ;
|
||||
static final ItemMetaKey LODESTONE_POS_Z = new ItemMetaKey("LodestonePosZ");
|
||||
static final ItemMetaKey LODESTONE_TRACKED = new ItemMetaKey("LodestoneTracked");
|
||||
|
||||
- private ResourceKey<net.minecraft.world.level.Level> lodestoneWorld;
|
||||
- private int lodestoneX;
|
||||
- private int lodestoneY;
|
||||
- private int lodestoneZ;
|
||||
- private boolean tracked = true;
|
||||
+ private Boolean tracked = null; // Paper - tri-state
|
||||
+ private LodestoneTracker tracker; // Paper - use LodestoneTracker type
|
||||
|
||||
CraftMetaCompass(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
return;
|
||||
}
|
||||
CraftMetaCompass compassMeta = (CraftMetaCompass) meta;
|
||||
- this.lodestoneWorld = compassMeta.lodestoneWorld;
|
||||
- this.lodestoneX = compassMeta.lodestoneX;
|
||||
- this.lodestoneY = compassMeta.lodestoneY;
|
||||
- this.lodestoneZ = compassMeta.lodestoneZ;
|
||||
- this.tracked = compassMeta.tracked;
|
||||
+ this.tracker = compassMeta.tracker; // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
CraftMetaCompass(DataComponentPatch tag, java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts) { // Paper
|
||||
super(tag, extraHandledDcts); // Paper
|
||||
getOrEmpty(tag, CraftMetaCompass.LODESTONE_TARGET).ifPresent((lodestoneTarget) -> {
|
||||
- lodestoneTarget.target().ifPresent((target) -> {
|
||||
- this.lodestoneWorld = target.dimension();
|
||||
- BlockPos pos = target.pos();
|
||||
- this.lodestoneX = pos.getX();
|
||||
- this.lodestoneY = pos.getY();
|
||||
- this.lodestoneZ = pos.getZ();
|
||||
- });
|
||||
- this.tracked = lodestoneTarget.tracked();
|
||||
+ this.tracker = lodestoneTarget; // Paper - use LodestoneTracker type
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
super(map);
|
||||
String lodestoneWorldString = SerializableMeta.getString(map, CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, true);
|
||||
if (lodestoneWorldString != null) {
|
||||
- this.lodestoneWorld = ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(lodestoneWorldString));
|
||||
- this.lodestoneX = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_X.BUKKIT);
|
||||
- this.lodestoneY = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT);
|
||||
- this.lodestoneZ = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT);
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ ResourceKey<net.minecraft.world.level.Level> lodestoneWorld = ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(lodestoneWorldString));
|
||||
+ int lodestoneX = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_X.BUKKIT);
|
||||
+ int lodestoneY = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT);
|
||||
+ int lodestoneZ = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT);
|
||||
+ this.tracker = new LodestoneTracker(Optional.of(new GlobalPos(lodestoneWorld, new BlockPos(lodestoneX, lodestoneY, lodestoneZ))), true);
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
} else {
|
||||
// legacy
|
||||
Location lodestone = SerializableMeta.getObject(Location.class, map, CraftMetaCompass.LODESTONE_POS.BUKKIT, true);
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
this.setLodestone(lodestone);
|
||||
}
|
||||
}
|
||||
- this.tracked = SerializableMeta.getBoolean(map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT);
|
||||
+ this.tracked = SerializableMeta.getObjectOptionally(Boolean.class, map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, true).orElse(null); // Paper - tri-state
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ final Optional<Boolean> tracked = SerializableMeta.getObjectOptionally(Boolean.class, map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, true);
|
||||
+ final Optional<GlobalPos> trackedPos = this.tracker != null ? this.tracker.target() : Optional.empty();
|
||||
+ tracked.ifPresent(isTracked -> this.tracker = new LodestoneTracker(trackedPos, isTracked));
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
void applyToItem(CraftMetaItem.Applicator tag) {
|
||||
super.applyToItem(tag);
|
||||
|
||||
- Optional<GlobalPos> target = Optional.empty();
|
||||
- if (this.lodestoneWorld != null) {
|
||||
- target = Optional.of(new GlobalPos(this.lodestoneWorld, new BlockPos(this.lodestoneX, this.lodestoneY, this.lodestoneZ)));
|
||||
- }
|
||||
-
|
||||
- if (target.isPresent() || this.hasLodestoneTracked()) {
|
||||
- tag.put(CraftMetaCompass.LODESTONE_TARGET, new LodestoneTracker(target, this.tracked));
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ if (this.tracker != null) {
|
||||
+ tag.put(CraftMetaCompass.LODESTONE_TARGET, this.tracker);
|
||||
}
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
}
|
||||
|
||||
boolean hasLodestoneTracked() {
|
||||
- return !this.tracked;
|
||||
+ return this.tracked != null; // Paper - tri-state
|
||||
boolean isCompassEmpty() {
|
||||
- return !(this.hasLodestone() || this.hasLodestoneTracked());
|
||||
+ return this.tracker == null; // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
|
||||
@Override
|
||||
public boolean hasLodestone() {
|
||||
- return this.lodestoneWorld != null;
|
||||
+ return this.tracker != null && this.tracker.target().isPresent(); // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLodestone() {
|
||||
- if (this.lodestoneWorld == null) {
|
||||
+ if (this.tracker == null || this.tracker.target().isEmpty()) { // Paper - use LodestoneTracker type
|
||||
return null;
|
||||
}
|
||||
- ServerLevel worldServer = MinecraftServer.getServer().getLevel(this.lodestoneWorld);
|
||||
+ ServerLevel worldServer = MinecraftServer.getServer().getLevel(this.tracker.target().get().dimension()); // Paper - use LodestoneTracker type
|
||||
World world = worldServer != null ? worldServer.getWorld() : null;
|
||||
- return new Location(world, this.lodestoneX, this.lodestoneY, this.lodestoneZ); // world may be null here, if the referenced world is not loaded
|
||||
+ return org.bukkit.craftbukkit.util.CraftLocation.toBukkit(this.tracker.target().get().pos(), world); // world may be null here, if the referenced world is not loaded // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLodestone(Location lodestone) {
|
||||
Preconditions.checkArgument(lodestone == null || lodestone.getWorld() != null, "world is null");
|
||||
if (lodestone == null) {
|
||||
- this.lodestoneWorld = null;
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ if (this.tracker != null) {
|
||||
+ this.tracker = new LodestoneTracker(java.util.Optional.empty(), this.tracker.tracked()); // Paper - use LodestoneTracker type
|
||||
+ }
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
} else {
|
||||
- this.lodestoneWorld = ((CraftWorld) lodestone.getWorld()).getHandle().dimension();
|
||||
- this.lodestoneX = lodestone.getBlockX();
|
||||
- this.lodestoneY = lodestone.getBlockY();
|
||||
- this.lodestoneZ = lodestone.getBlockZ();
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ GlobalPos pos = GlobalPos.of(
|
||||
+ ((CraftWorld) lodestone.getWorld()).getHandle().dimension(),
|
||||
+ io.papermc.paper.util.MCUtil.toBlockPosition(lodestone)
|
||||
+ );
|
||||
+ boolean tracked = this.tracker == null || this.tracker.tracked();
|
||||
+ this.tracker = new LodestoneTracker(Optional.of(pos), tracked);
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
}
|
||||
}
|
||||
|
||||
- boolean hasLodestoneTracked() {
|
||||
- return !this.tracked;
|
||||
- }
|
||||
-
|
||||
@Override
|
||||
public boolean isLodestoneTracked() {
|
||||
- return this.tracked;
|
||||
+ return this.tracked != null && this.tracked; // Paper - tri-state
|
||||
+ return this.tracker != null && this.tracker.tracked(); // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLodestoneTracked(boolean tracked) {
|
||||
- this.tracked = tracked;
|
||||
+ final Optional<GlobalPos> trackedPos = this.tracker != null ? this.tracker.target() : Optional.empty(); // Paper - use LodestoneTracker type
|
||||
+ this.tracker = new LodestoneTracker(trackedPos, tracked); // Paper - use LodestoneTracker type
|
||||
+ }
|
||||
+
|
||||
+ // Paper start - Add more lodestone compass methods
|
||||
+ @Override
|
||||
+ public boolean isLodestoneCompass() {
|
||||
+ return this.tracker != null;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void clearLodestone() {
|
||||
+ this.tracker = null;
|
||||
}
|
||||
+ // Paper end - Add more lodestone compass methods
|
||||
|
||||
@Override
|
||||
int applyHash() {
|
||||
final int original;
|
||||
int hash = original = super.applyHash();
|
||||
- if (this.hasLodestone()) {
|
||||
- hash = 73 * hash + this.lodestoneWorld.hashCode();
|
||||
- hash = 73 * hash + this.lodestoneX;
|
||||
- hash = 73 * hash + this.lodestoneY;
|
||||
- hash = 73 * hash + this.lodestoneZ;
|
||||
- }
|
||||
- if (this.hasLodestoneTracked()) {
|
||||
- hash = 73 * hash + (this.isLodestoneTracked() ? 1231 : 1237);
|
||||
+ if (this.isLodestoneCompass()) {
|
||||
+ hash = 73 * hash + this.tracker.hashCode(); // Paper - use LodestoneTracker type
|
||||
}
|
||||
|
||||
return original != hash ? CraftMetaCompass.class.hashCode() ^ hash : hash;
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
if (meta instanceof CraftMetaCompass) {
|
||||
CraftMetaCompass that = (CraftMetaCompass) meta;
|
||||
|
||||
- return (this.hasLodestone() ? that.hasLodestone() && this.lodestoneWorld.equals(that.lodestoneWorld)
|
||||
- && this.lodestoneX == that.lodestoneX && this.lodestoneY == that.lodestoneY
|
||||
- && this.lodestoneZ == that.lodestoneZ : !that.hasLodestone())
|
||||
- && this.tracked == that.tracked;
|
||||
+ return java.util.Objects.equals(this.tracker, that.tracker); // Paper - use LodestoneTracker type
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
|
||||
Builder<String, Object> serialize(Builder<String, Object> builder) {
|
||||
super.serialize(builder);
|
||||
|
||||
- if (this.hasLodestone()) {
|
||||
- builder.put(CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, this.lodestoneWorld.location().toString());
|
||||
- builder.put(CraftMetaCompass.LODESTONE_POS_X.BUKKIT, this.lodestoneX);
|
||||
- builder.put(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT, this.lodestoneY);
|
||||
- builder.put(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT, this.lodestoneZ);
|
||||
- }
|
||||
- if (this.hasLodestoneTracked()) {
|
||||
- builder.put(CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, this.tracked);
|
||||
+ if (this.isLodestoneCompass()) { // Paper - use LodestoneTracker type
|
||||
+ // Paper start - use LodestoneTracker type
|
||||
+ if (this.tracker.target().isPresent()) {
|
||||
+ builder.put(CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, this.tracker.target().get().dimension().location().toString());
|
||||
+ builder.put(CraftMetaCompass.LODESTONE_POS_X.BUKKIT, this.tracker.target().get().pos().getX());
|
||||
+ builder.put(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT, this.tracker.target().get().pos().getY());
|
||||
+ builder.put(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT, this.tracker.target().get().pos().getZ());
|
||||
+ }
|
||||
+ builder.put(CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, this.tracker.tracked());
|
||||
+ // Paper end - use LodestoneTracker type
|
||||
}
|
||||
|
||||
return builder;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java
|
||||
|
|
|
@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
if (!blockList.getBlockState(blockposition_mutableblockposition1).is(block)) {
|
||||
if (flag) {
|
||||
- blockList.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null);
|
||||
+ // blockList.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null); // Paper - moved down - cb implementation of LevelAccessor does not support destoryBlock
|
||||
+ // blockList.destroyBlock(blockposition_mutableblockposition1, true, (Entity) null); // Paper - moved down - cb implementation of LevelAccessor does not support destroyBlock
|
||||
}
|
||||
|
||||
blockList.setBlock(blockposition_mutableblockposition1, block.defaultBlockState(), 3);
|
||||
|
|
Loading…
Reference in a new issue