Skip to content

Commit

Permalink
Restore ability to mark item as collectible without owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jul 30, 2024
1 parent 730b4f3 commit 350b342
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static boolean isCollectible(ItemStack stack) {

public static boolean isIllegalCollectible(ItemStack stack, Player player) {
CollectibleMarker marker = stack.get(ExtraDataComponents.COLLECTIBLE);
return marker != null && !player.getUUID().equals(marker.ownerId());
if (marker == null) {
return false;
}
return marker.ownerId().isPresent() && !player.getUUID().equals(marker.ownerId().get());
}

public static ItemStack createItemStack(Holder<Collectible> collectible, UUID player) {
Expand All @@ -79,7 +82,7 @@ public static ItemStack createItemStack(Holder<Collectible> collectible, UUID pl
public static void addMarkerTo(UUID player, Holder<Collectible> collectible, ItemStack stack) {
stack.set(ExtraDataComponents.COLLECTIBLE, new CollectibleMarker(
collectible.kind() == Holder.Kind.REFERENCE ? Optional.of(collectible) : Optional.empty(),
player
Optional.of(player)
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

public record CollectibleMarker(
Optional<Holder<Collectible>> collectible,
UUID ownerId
Optional<UUID> ownerId
) {
public static final Codec<CollectibleMarker> CODEC = RecordCodecBuilder.create(i -> i.group(
Collectible.CODEC.optionalFieldOf("id").forGetter(CollectibleMarker::collectible),
UUIDUtil.CODEC.fieldOf("owner").forGetter(CollectibleMarker::ownerId)
UUIDUtil.CODEC.optionalFieldOf("owner").forGetter(CollectibleMarker::ownerId)
).apply(i, CollectibleMarker::new));

public static final StreamCodec<RegistryFriendlyByteBuf, CollectibleMarker> STREAM_CODEC = StreamCodec.composite(
Collectible.STREAM_CODEC.apply(ByteBufCodecs::optional), CollectibleMarker::collectible,
UUIDUtil.STREAM_CODEC, CollectibleMarker::ownerId,
UUIDUtil.STREAM_CODEC.apply(ByteBufCodecs::optional), CollectibleMarker::ownerId,
CollectibleMarker::new
);
}

0 comments on commit 350b342

Please sign in to comment.