-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MrBunnyDc
committed
Sep 27, 2024
1 parent
cb92c02
commit 7e5daff
Showing
11 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/WgcValueTypeRegistry.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,39 @@ | ||
package de.wonejo.wuidebook.api.wgc; | ||
|
||
import de.wonejo.wuidebook.api.wgc.value.WgcTagValue; | ||
import de.wonejo.wuidebook.api.wgc.value.WgcValueTagType; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
public class WgcValueTypeRegistry { | ||
private static WgcValueTypeRegistry INSTANCE; | ||
|
||
public static WgcValueTypeRegistry get () { | ||
if ( WgcValueTypeRegistry.INSTANCE == null ) WgcValueTypeRegistry.INSTANCE = new WgcValueTypeRegistry(); | ||
return WgcValueTypeRegistry.INSTANCE; | ||
} | ||
|
||
private final Map<ResourceLocation, Function<String, WgcTagValue<?>>> tagValues = new HashMap<>(); | ||
|
||
private WgcValueTypeRegistry () {} | ||
|
||
public <T> void registerType( ResourceLocation typeName, Function<String, WgcTagValue<?>> valueCreator ) { | ||
tagValues.put(typeName, valueCreator); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> WgcTagValue<T> createTagValue ( ResourceLocation pInputType, String pValue ) { | ||
Function<String, WgcTagValue<?>> valueCreator = this.tagValues.get(pInputType); | ||
if ( valueCreator == null ) throw new RuntimeException("No matching tag value creator found for type: " + pInputType); | ||
return (WgcTagValue<T>) valueCreator.apply(pValue); | ||
} | ||
|
||
public <T> WgcTagValue<T> createTagValue (@NotNull WgcValueTagType<T> pInputType, String pValue ) { | ||
return this.createTagValue(pInputType.id(), pValue); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/BooleanWgcValue.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,27 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
import de.wonejo.wuidebook.api.util.TriState; | ||
|
||
public final class BooleanWgcValue implements WgcTagValue<TriState> { | ||
public static final WgcValueTagType<TriState> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_bool"), TriState.class); | ||
|
||
private final TriState boolState; | ||
|
||
public BooleanWgcValue(TriState pBoolState) { | ||
this.boolState = pBoolState; | ||
} | ||
|
||
public WgcTagValue<TriState> copy() { | ||
return new BooleanWgcValue(this.boolState); | ||
} | ||
|
||
public WgcValueTagType<TriState> type() { | ||
return TYPE; | ||
} | ||
|
||
public TriState getValue() { | ||
return this.boolState; | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/ByteWgcValue.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,31 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class ByteWgcValue implements WgcNumericTagValue<Byte> { | ||
public static final WgcValueTagType<Byte> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_byte"), Byte.class); | ||
|
||
private final byte value; | ||
|
||
public ByteWgcValue(byte pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
public Number getAsNumber() { | ||
return this.value; | ||
} | ||
|
||
@NotNull public WgcTagValue<Byte> copy() { | ||
return new ByteWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<Byte> type() { | ||
return TYPE; | ||
} | ||
|
||
public Byte getValue() { | ||
return this.value; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/DoubleWgcValue.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,30 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class DoubleWgcValue implements WgcNumericTagValue<Double> { | ||
public static final WgcValueTagType<Double> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_double"), Double.class); | ||
|
||
private final double value; | ||
|
||
public DoubleWgcValue(double pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
public Number getAsNumber() { | ||
return this.value; | ||
} | ||
|
||
@NotNull public WgcTagValue<Double> copy() { | ||
return new DoubleWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<Double> type() { | ||
return TYPE; | ||
} | ||
|
||
public Double getValue() { | ||
return this.value; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/FloatWgcValue.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,30 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class FloatWgcValue implements WgcNumericTagValue<Float> { | ||
public static final WgcValueTagType<Float> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_float"), Float.class); | ||
|
||
private final float value; | ||
|
||
public FloatWgcValue(float pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
public Number getAsNumber() { | ||
return this.value; | ||
} | ||
|
||
@NotNull public WgcTagValue<Float> copy() { | ||
return new FloatWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<Float> type() { | ||
return TYPE; | ||
} | ||
|
||
public Float getValue() { | ||
return this.value; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/IntWgcValue.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,33 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
|
||
public final class IntWgcValue implements WgcNumericTagValue<Integer> { | ||
public static final WgcValueTagType<Integer> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_int"), Integer.class); | ||
|
||
private final int value; | ||
|
||
public IntWgcValue(int pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
public Number getAsNumber() { | ||
return this.value; | ||
} | ||
|
||
public WgcTagValue<Integer> copy() { | ||
return new IntWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<Integer> type() { | ||
return TYPE; | ||
} | ||
|
||
public Integer getValue() { | ||
return this.value; | ||
} | ||
|
||
public String toString() { | ||
return "int(" + this.value + ")"; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/ShortWgcValue.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,29 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
|
||
public final class ShortWgcValue implements WgcNumericTagValue<Short> { | ||
public static final WgcValueTagType<Short> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_short"), Short.class); | ||
|
||
private final short value; | ||
|
||
public ShortWgcValue(short pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
public Number getAsNumber() { | ||
return this.value; | ||
} | ||
|
||
public WgcTagValue<Short> copy() { | ||
return new ShortWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<Short> type() { | ||
return TYPE; | ||
} | ||
|
||
public Short getValue() { | ||
return this.value; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/StringWgcValue.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,26 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class StringWgcValue implements WgcTagValue<String> { | ||
public static final WgcValueTagType<String> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_str"), String.class); | ||
|
||
private final String value; | ||
|
||
public StringWgcValue(String pValue) { | ||
this.value = pValue; | ||
} | ||
|
||
@NotNull public WgcTagValue<String> copy() { | ||
return new StringWgcValue(this.value); | ||
} | ||
|
||
public WgcValueTagType<String> type() { | ||
return TYPE; | ||
} | ||
|
||
public String getValue() { | ||
return this.value; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/WgcNumericTagValue.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,13 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
public interface WgcNumericTagValue<T extends Number> extends WgcTagValue<T> { | ||
|
||
default byte getAsByte () { return this.getAsNumber().byteValue(); } | ||
default short getAsShort () { return this.getAsNumber().shortValue(); } | ||
default int getAsInt () { return this.getAsNumber().intValue(); } | ||
default float getAsFloat () { return this.getAsNumber().floatValue(); } | ||
default double getAsDouble () { return this.getAsNumber().doubleValue(); } | ||
|
||
Number getAsNumber (); | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/WgcTagValue.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,15 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
|
||
public interface WgcTagValue<T> { | ||
|
||
default String getAsString () { return this.toString(); } | ||
|
||
WgcTagValue<T> copy (); | ||
WgcValueTagType<T> type (); | ||
|
||
T getValue (); | ||
|
||
String toString (); | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/WgcValueTagType.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,6 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public record WgcValueTagType<T>(ResourceLocation id, Class<T> classType) { | ||
} |