@@ -596,42 +596,237 @@ index 6517ec4933b0eae761fceb117ea1db175755d0b1..299f2f4f143f753f3cd8a020c8e6ae46
596
596
return true;
597
597
}
598
598
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java
599
- index 69a112b3a9726966aecbe687d905fd1a11cfa1e3..6362df65424e53098701b8d54c74b5905648b78a 100644
599
+ index 69a112b3a9726966aecbe687d905fd1a11cfa1e3..ab424926c282fb03eabd1eebd2b7980899ef28e3 100644
600
600
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java
601
601
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java
602
- @@ -35,7 +35,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
603
- private int lodestoneX;
604
- private int lodestoneY;
605
- private int lodestoneZ;
602
+ @@ -31,11 +31,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
603
+ static final ItemMetaKey LODESTONE_POS_Z = new ItemMetaKey("LodestonePosZ");
604
+ static final ItemMetaKey LODESTONE_TRACKED = new ItemMetaKey("LodestoneTracked");
605
+
606
+ - private ResourceKey<net.minecraft.world.level.Level> lodestoneWorld;
607
+ - private int lodestoneX;
608
+ - private int lodestoneY;
609
+ - private int lodestoneZ;
606
610
- private boolean tracked = true;
607
- + private Boolean tracked = null ; // Paper - tri-state
611
+ + private LodestoneTracker tracker ; // Paper - use LodestoneTracker type
608
612
609
613
CraftMetaCompass(CraftMetaItem meta) {
610
614
super(meta);
611
- @@ -79,7 +79,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
615
+ @@ -43,24 +39,13 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
616
+ return;
617
+ }
618
+ CraftMetaCompass compassMeta = (CraftMetaCompass) meta;
619
+ - this.lodestoneWorld = compassMeta.lodestoneWorld;
620
+ - this.lodestoneX = compassMeta.lodestoneX;
621
+ - this.lodestoneY = compassMeta.lodestoneY;
622
+ - this.lodestoneZ = compassMeta.lodestoneZ;
623
+ - this.tracked = compassMeta.tracked;
624
+ + this.tracker = compassMeta.tracker; // Paper - use LodestoneTracker type
625
+ }
626
+
627
+ CraftMetaCompass(DataComponentPatch tag, java.util.Set<net.minecraft.core.component.DataComponentType<?>> extraHandledDcts) { // Paper
628
+ super(tag, extraHandledDcts); // Paper
629
+ getOrEmpty(tag, CraftMetaCompass.LODESTONE_TARGET).ifPresent((lodestoneTarget) -> {
630
+ - lodestoneTarget.target().ifPresent((target) -> {
631
+ - this.lodestoneWorld = target.dimension();
632
+ - BlockPos pos = target.pos();
633
+ - this.lodestoneX = pos.getX();
634
+ - this.lodestoneY = pos.getY();
635
+ - this.lodestoneZ = pos.getZ();
636
+ - });
637
+ - this.tracked = lodestoneTarget.tracked();
638
+ + this.tracker = lodestoneTarget; // Paper - use LodestoneTracker type
639
+ });
640
+ }
641
+
642
+ @@ -68,10 +53,13 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
643
+ super(map);
644
+ String lodestoneWorldString = SerializableMeta.getString(map, CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, true);
645
+ if (lodestoneWorldString != null) {
646
+ - this.lodestoneWorld = ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(lodestoneWorldString));
647
+ - this.lodestoneX = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_X.BUKKIT);
648
+ - this.lodestoneY = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT);
649
+ - this.lodestoneZ = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT);
650
+ + // Paper start - use LodestoneTracker type
651
+ + ResourceKey<net.minecraft.world.level.Level> lodestoneWorld = ResourceKey.create(Registries.DIMENSION, ResourceLocation.tryParse(lodestoneWorldString));
652
+ + int lodestoneX = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_X.BUKKIT);
653
+ + int lodestoneY = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT);
654
+ + int lodestoneZ = (Integer) map.get(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT);
655
+ + this.tracker = new LodestoneTracker(Optional.of(new GlobalPos(lodestoneWorld, new BlockPos(lodestoneX, lodestoneY, lodestoneZ))), true);
656
+ + // Paper end - use LodestoneTracker type
657
+ } else {
658
+ // legacy
659
+ Location lodestone = SerializableMeta.getObject(Location.class, map, CraftMetaCompass.LODESTONE_POS.BUKKIT, true);
660
+ @@ -79,21 +67,22 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
612
661
this.setLodestone(lodestone);
613
662
}
614
663
}
615
664
- this.tracked = SerializableMeta.getBoolean(map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT);
616
- + this.tracked = SerializableMeta.getObjectOptionally(Boolean.class, map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, true).orElse(null); // Paper - tri-state
665
+ + // Paper start - use LodestoneTracker type
666
+ + final Optional<Boolean> tracked = SerializableMeta.getObjectOptionally(Boolean.class, map, CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, true);
667
+ + final Optional<GlobalPos> trackedPos = this.tracker != null ? this.tracker.target() : Optional.empty();
668
+ + tracked.ifPresent(isTracked -> this.tracker = new LodestoneTracker(trackedPos, isTracked));
669
+ + // Paper end - use LodestoneTracker type
617
670
}
618
671
619
672
@Override
620
- @@ -140,12 +140,12 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
673
+ void applyToItem(CraftMetaItem.Applicator tag) {
674
+ super.applyToItem(tag);
675
+
676
+ - Optional<GlobalPos> target = Optional.empty();
677
+ - if (this.lodestoneWorld != null) {
678
+ - target = Optional.of(new GlobalPos(this.lodestoneWorld, new BlockPos(this.lodestoneX, this.lodestoneY, this.lodestoneZ)));
679
+ - }
680
+ -
681
+ - if (target.isPresent() || this.hasLodestoneTracked()) {
682
+ - tag.put(CraftMetaCompass.LODESTONE_TARGET, new LodestoneTracker(target, this.tracked));
683
+ + // Paper start - use LodestoneTracker type
684
+ + if (this.tracker != null) {
685
+ + tag.put(CraftMetaCompass.LODESTONE_TARGET, this.tracker);
686
+ }
687
+ + // Paper end - use LodestoneTracker type
621
688
}
622
689
623
- boolean hasLodestoneTracked() {
624
- - return !this.tracked;
625
- + return this.tracked != null; // Paper - tri-state
690
+ @Override
691
+ @@ -102,7 +91,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
692
+ }
693
+
694
+ boolean isCompassEmpty() {
695
+ - return !(this.hasLodestone() || this.hasLodestoneTracked());
696
+ + return this.tracker == null; // Paper - use LodestoneTracker type
697
+ }
698
+
699
+ @Override
700
+ @@ -113,58 +102,69 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
701
+
702
+ @Override
703
+ public boolean hasLodestone() {
704
+ - return this.lodestoneWorld != null;
705
+ + return this.tracker != null && this.tracker.target().isPresent(); // Paper - use LodestoneTracker type
706
+ }
707
+
708
+ @Override
709
+ public Location getLodestone() {
710
+ - if (this.lodestoneWorld == null) {
711
+ + if (this.tracker == null || this.tracker.target().isEmpty()) { // Paper - use LodestoneTracker type
712
+ return null;
713
+ }
714
+ - ServerLevel worldServer = MinecraftServer.getServer().getLevel(this.lodestoneWorld);
715
+ + ServerLevel worldServer = MinecraftServer.getServer().getLevel(this.tracker.target().get().dimension()); // Paper - use LodestoneTracker type
716
+ World world = worldServer != null ? worldServer.getWorld() : null;
717
+ - return new Location(world, this.lodestoneX, this.lodestoneY, this.lodestoneZ); // world may be null here, if the referenced world is not loaded
718
+ + 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
719
+ }
720
+
721
+ @Override
722
+ public void setLodestone(Location lodestone) {
723
+ Preconditions.checkArgument(lodestone == null || lodestone.getWorld() != null, "world is null");
724
+ if (lodestone == null) {
725
+ - this.lodestoneWorld = null;
726
+ + // Paper start - use LodestoneTracker type
727
+ + if (this.tracker != null) {
728
+ + this.tracker = new LodestoneTracker(java.util.Optional.empty(), this.tracker.tracked()); // Paper - use LodestoneTracker type
729
+ + }
730
+ + // Paper end - use LodestoneTracker type
731
+ } else {
732
+ - this.lodestoneWorld = ((CraftWorld) lodestone.getWorld()).getHandle().dimension();
733
+ - this.lodestoneX = lodestone.getBlockX();
734
+ - this.lodestoneY = lodestone.getBlockY();
735
+ - this.lodestoneZ = lodestone.getBlockZ();
736
+ + // Paper start - use LodestoneTracker type
737
+ + GlobalPos pos = GlobalPos.of(
738
+ + ((CraftWorld) lodestone.getWorld()).getHandle().dimension(),
739
+ + io.papermc.paper.util.MCUtil.toBlockPosition(lodestone)
740
+ + );
741
+ + boolean tracked = this.tracker == null || this.tracker.tracked();
742
+ + this.tracker = new LodestoneTracker(Optional.of(pos), tracked);
743
+ + // Paper end - use LodestoneTracker type
744
+ }
626
745
}
627
746
747
+ - boolean hasLodestoneTracked() {
748
+ - return !this.tracked;
749
+ - }
750
+ -
628
751
@Override
629
752
public boolean isLodestoneTracked() {
630
753
- return this.tracked;
631
- + return this.tracked != null && this.tracked; // Paper - tri-state
754
+ + return this.tracker != null && this.tracker.tracked(); // Paper - use LodestoneTracker type
755
+ }
756
+
757
+ @Override
758
+ public void setLodestoneTracked(boolean tracked) {
759
+ - this.tracked = tracked;
760
+ + final Optional<GlobalPos> trackedPos = this.tracker != null ? this.tracker.target() : Optional.empty(); // Paper - use LodestoneTracker type
761
+ + this.tracker = new LodestoneTracker(trackedPos, tracked); // Paper - use LodestoneTracker type
762
+ + }
763
+ +
764
+ + // Paper start - Add more lodestone compass methods
765
+ + @Override
766
+ + public boolean isLodestoneCompass() {
767
+ + return this.tracker != null;
768
+ + }
769
+ +
770
+ + @Override
771
+ + public void clearLodestone() {
772
+ + this.tracker = null;
632
773
}
774
+ + // Paper end - Add more lodestone compass methods
633
775
634
776
@Override
777
+ int applyHash() {
778
+ final int original;
779
+ int hash = original = super.applyHash();
780
+ - if (this.hasLodestone()) {
781
+ - hash = 73 * hash + this.lodestoneWorld.hashCode();
782
+ - hash = 73 * hash + this.lodestoneX;
783
+ - hash = 73 * hash + this.lodestoneY;
784
+ - hash = 73 * hash + this.lodestoneZ;
785
+ - }
786
+ - if (this.hasLodestoneTracked()) {
787
+ - hash = 73 * hash + (this.isLodestoneTracked() ? 1231 : 1237);
788
+ + if (this.isLodestoneCompass()) {
789
+ + hash = 73 * hash + this.tracker.hashCode(); // Paper - use LodestoneTracker type
790
+ }
791
+
792
+ return original != hash ? CraftMetaCompass.class.hashCode() ^ hash : hash;
793
+ @@ -178,10 +178,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
794
+ if (meta instanceof CraftMetaCompass) {
795
+ CraftMetaCompass that = (CraftMetaCompass) meta;
796
+
797
+ - return (this.hasLodestone() ? that.hasLodestone() && this.lodestoneWorld.equals(that.lodestoneWorld)
798
+ - && this.lodestoneX == that.lodestoneX && this.lodestoneY == that.lodestoneY
799
+ - && this.lodestoneZ == that.lodestoneZ : !that.hasLodestone())
800
+ - && this.tracked == that.tracked;
801
+ + return java.util.Objects.equals(this.tracker, that.tracker); // Paper - use LodestoneTracker type
802
+ }
803
+ return true;
804
+ }
805
+ @@ -195,14 +192,16 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta {
806
+ Builder<String, Object> serialize(Builder<String, Object> builder) {
807
+ super.serialize(builder);
808
+
809
+ - if (this.hasLodestone()) {
810
+ - builder.put(CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, this.lodestoneWorld.location().toString());
811
+ - builder.put(CraftMetaCompass.LODESTONE_POS_X.BUKKIT, this.lodestoneX);
812
+ - builder.put(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT, this.lodestoneY);
813
+ - builder.put(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT, this.lodestoneZ);
814
+ - }
815
+ - if (this.hasLodestoneTracked()) {
816
+ - builder.put(CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, this.tracked);
817
+ + if (this.isLodestoneCompass()) { // Paper - use LodestoneTracker type
818
+ + // Paper start - use LodestoneTracker type
819
+ + if (this.tracker.target().isPresent()) {
820
+ + builder.put(CraftMetaCompass.LODESTONE_POS_WORLD.BUKKIT, this.tracker.target().get().dimension().location().toString());
821
+ + builder.put(CraftMetaCompass.LODESTONE_POS_X.BUKKIT, this.tracker.target().get().pos().getX());
822
+ + builder.put(CraftMetaCompass.LODESTONE_POS_Y.BUKKIT, this.tracker.target().get().pos().getY());
823
+ + builder.put(CraftMetaCompass.LODESTONE_POS_Z.BUKKIT, this.tracker.target().get().pos().getZ());
824
+ + }
825
+ + builder.put(CraftMetaCompass.LODESTONE_TRACKED.BUKKIT, this.tracker.tracked());
826
+ + // Paper end - use LodestoneTracker type
827
+ }
828
+
829
+ return builder;
635
830
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java
636
831
index 0807c2172c5a4bee675cef265a45a9350e98b880..88ea260fb84a5f8eaab3a23a9a65d0411215a6a1 100644
637
832
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java
0 commit comments