-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement HolderSet class and cleanup item codec (#818)
* 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
1 parent
a1b559d
commit a724a8f
Showing
4 changed files
with
134 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/HolderSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.