Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HolderSet class and cleanup item codec #818

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading