Skip to content

Commit 1ce84cd

Browse files
Add enchantment_glint_override component reader
1 parent 45a6a7e commit 1ce84cd

4 files changed

Lines changed: 99 additions & 8 deletions

File tree

core/src/main/java/org/geysermc/geyser/registry/mappings/components/DataComponentReaders.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
3333
import org.geysermc.geyser.api.util.Identifier;
3434
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
35+
import org.geysermc.geyser.registry.mappings.components.readers.BooleanComponentReader;
3536
import org.geysermc.geyser.registry.mappings.components.readers.ConsumableReader;
3637
import org.geysermc.geyser.registry.mappings.components.readers.EnchantableReader;
3738
import org.geysermc.geyser.registry.mappings.components.readers.EquippableReader;
@@ -72,5 +73,6 @@ public static void readDataComponent(CustomItemDefinition.Builder builder, Strin
7273
READERS.put(MinecraftKey.key("enchantable"), new EnchantableReader());
7374
READERS.put(MinecraftKey.key("tool"), new ToolPropertiesReader());
7475
READERS.put(MinecraftKey.key("repairable"), new RepairableReader());
76+
READERS.put(MinecraftKey.key("enchantment_glint_override"), new BooleanComponentReader(DataComponent.ENCHANTMENT_GLINT_OVERRIDE));
7577
}
7678
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.registry.mappings.components.readers;
27+
28+
import com.google.gson.JsonPrimitive;
29+
import org.checkerframework.checker.nullness.qual.NonNull;
30+
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
31+
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
32+
import org.geysermc.geyser.registry.mappings.util.NodeReader;
33+
34+
public class BooleanComponentReader extends PrimitiveComponentReader<Boolean> {
35+
36+
public BooleanComponentReader(DataComponent<Boolean> type) {
37+
super(type);
38+
}
39+
40+
@Override
41+
protected Boolean readValue(@NonNull JsonPrimitive primitive, String... context) throws InvalidCustomMappingsFileException {
42+
return NodeReader.BOOLEAN.read(primitive, "reading component", context);
43+
}
44+
}

core/src/main/java/org/geysermc/geyser/registry/mappings/components/readers/IntComponentReader.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525

2626
package org.geysermc.geyser.registry.mappings.components.readers;
2727

28-
import com.google.gson.JsonElement;
2928
import com.google.gson.JsonPrimitive;
3029
import org.checkerframework.checker.nullness.qual.NonNull;
3130
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
3231
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
33-
import org.geysermc.geyser.registry.mappings.components.DataComponentReader;
3432
import org.geysermc.geyser.registry.mappings.util.NodeReader;
3533

36-
public class IntComponentReader extends DataComponentReader<Integer> {
34+
public class IntComponentReader extends PrimitiveComponentReader<Integer> {
3735
private final int minimum;
3836
private final int maximum;
3937

@@ -48,10 +46,7 @@ public IntComponentReader(DataComponent<Integer> type, int minimum) {
4846
}
4947

5048
@Override
51-
protected Integer readDataComponent(@NonNull JsonElement element, String... context) throws InvalidCustomMappingsFileException {
52-
if (!element.isJsonPrimitive()) {
53-
throw new InvalidCustomMappingsFileException("reading component", "value must be a primitive", context);
54-
}
55-
return NodeReader.boundedInt(minimum, maximum).read((JsonPrimitive) element, "reading component", context);
49+
protected Integer readValue(@NonNull JsonPrimitive primitive, String... context) throws InvalidCustomMappingsFileException {
50+
return NodeReader.boundedInt(minimum, maximum).read(primitive, "reading component", context);
5651
}
5752
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2025 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.registry.mappings.components.readers;
27+
28+
import com.google.gson.JsonElement;
29+
import com.google.gson.JsonPrimitive;
30+
import org.checkerframework.checker.nullness.qual.NonNull;
31+
import org.geysermc.geyser.api.item.custom.v2.component.DataComponent;
32+
import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException;
33+
import org.geysermc.geyser.registry.mappings.components.DataComponentReader;
34+
35+
public abstract class PrimitiveComponentReader<V> extends DataComponentReader<V> {
36+
37+
protected PrimitiveComponentReader(DataComponent<V> type) {
38+
super(type);
39+
}
40+
41+
protected abstract V readValue(@NonNull JsonPrimitive primitive, String... context) throws InvalidCustomMappingsFileException;
42+
43+
@Override
44+
protected V readDataComponent(@NonNull JsonElement element, String... context) throws InvalidCustomMappingsFileException {
45+
if (!element.isJsonPrimitive()) {
46+
throw new InvalidCustomMappingsFileException("reading component", "value must be a primitive", context);
47+
}
48+
return readValue((JsonPrimitive) element, context);
49+
}
50+
}

0 commit comments

Comments
 (0)