Skip to content

Commit

Permalink
Implement HolderSet class and cleanup item codec (#818)
Browse files Browse the repository at this point in the history
* Implement HolderSet class and cleanup item codec

* Also validate both being set case

* Fix equals and hashcode by migrating from a record to a class

* Change field names to match vanilla
  • Loading branch information
AlexProgrammerDE authored May 20, 2024
1 parent a1b559d commit a724a8f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class AdventureModePredicate {
@Data
@AllArgsConstructor
public static class BlockPredicate {
private final @Nullable String location;
private final int @Nullable [] holders;
private final @Nullable HolderSet blocks;
private final @Nullable List<PropertyMatcher> properties;
private final @Nullable NbtMap nbt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.geysermc.mcprotocollib.protocol.data.game.item.component;

import lombok.Data;
import lombok.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.function.Function;

/**
* Represents a set of holders that could either be explicit, or resolved from a tag location.
* The client has to know how to resolve the tag location to get the holders.
*/
@Data
public final class HolderSet {
private final @Nullable String location;
private final int @Nullable [] holders;

public HolderSet(int @NonNull [] holders) {
this.location = null;
this.holders = holders;
}

public HolderSet(@NonNull String location) {
this.location = location;
this.holders = null;
}

/**
* Return either the explicit holders, or resolve the tag location to get the holders.
*
* @param tagResolver The function to resolve the tag location to get the holders.
* @return The holders.
*/
public int[] resolve(Function<String, int[]> tagResolver) {
if (holders != null) {
return holders;
}

return tagResolver.apply(location);
}
}
Loading

0 comments on commit a724a8f

Please sign in to comment.