mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Use IllegalArgumentException instead of asserting and make TagRegistry#getVanillaTags return original map
This commit is contained in:
parent
7fa4f27c5a
commit
1c5819328a
2 changed files with 14 additions and 6 deletions
|
@ -118,7 +118,9 @@ public final class TagCache {
|
||||||
* @return true if the block tag is present and contains this block mapping's Java ID.
|
* @return true if the block tag is present and contains this block mapping's Java ID.
|
||||||
*/
|
*/
|
||||||
public boolean is(Tag tag, Block block) {
|
public boolean is(Tag tag, Block block) {
|
||||||
assert tag.registry() == TagRegistry.BLOCK;
|
if (tag.registry() != TagRegistry.BLOCK) {
|
||||||
|
throw new IllegalArgumentException("Given tag is not a block tag! (tag registry=%s)".formatted(tag.registry()));
|
||||||
|
}
|
||||||
return contains(get(tag), block.javaId());
|
return contains(get(tag), block.javaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +135,9 @@ public final class TagCache {
|
||||||
* @return true if the item tag is present and contains this item's Java ID.
|
* @return true if the item tag is present and contains this item's Java ID.
|
||||||
*/
|
*/
|
||||||
public boolean is(Tag tag, Item item) {
|
public boolean is(Tag tag, Item item) {
|
||||||
assert tag.registry() == TagRegistry.ITEM;
|
if (tag.registry() != TagRegistry.ITEM) {
|
||||||
|
throw new IllegalArgumentException("Given tag is not an item tag! (tag registry=%s)".formatted(tag.registry()));
|
||||||
|
}
|
||||||
return contains(get(tag), item.javaId());
|
return contains(get(tag), item.javaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ package org.geysermc.geyser.session.cache.tags;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.Getter;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.geysermc.geyser.util.MinecraftKey;
|
import org.geysermc.geyser.util.MinecraftKey;
|
||||||
|
@ -44,6 +45,13 @@ public enum TagRegistry {
|
||||||
ENCHANTMENT("enchantment");
|
ENCHANTMENT("enchantment");
|
||||||
|
|
||||||
private final Key registryKey;
|
private final Key registryKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A map mapping vanilla tag keys in this registry to a {@link Tag} instance (this is a {@link VanillaTag}).
|
||||||
|
*
|
||||||
|
* Keys should never be manually added to this map. Rather, {@link TagRegistry#registerVanillaTag} should be used, during Geyser init.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
private final Map<Key, Tag> vanillaTags;
|
private final Map<Key, Tag> vanillaTags;
|
||||||
|
|
||||||
TagRegistry(String registry) {
|
TagRegistry(String registry) {
|
||||||
|
@ -61,10 +69,6 @@ public enum TagRegistry {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Key, Tag> getVanillaTags() {
|
|
||||||
return Map.copyOf(vanillaTags);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static TagRegistry fromKey(Key registryKey) {
|
public static TagRegistry fromKey(Key registryKey) {
|
||||||
for (TagRegistry registry : TagRegistry.values()) {
|
for (TagRegistry registry : TagRegistry.values()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue