-
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
7f7b144
commit 30fdd7c
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
XPlat/src/main/java/de/wonejo/wuidebook/api/util/InvalidWgcFormatException.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,21 @@ | ||
package de.wonejo.wuidebook.api.util; | ||
|
||
public class InvalidWgcFormatException extends RuntimeException { | ||
|
||
public InvalidWgcFormatException ( String pMessage, int pCodeLine, Throwable pThrowable ) { | ||
super("An error occurred on line: " + pCodeLine + " of a Wgc file: " + pMessage, pThrowable); | ||
} | ||
|
||
public InvalidWgcFormatException ( String pMessage, int pCodeLine ) { | ||
super("An error occurred on line: " + pCodeLine + " of a Wgc file: " + pMessage); | ||
} | ||
|
||
public InvalidWgcFormatException ( String pMessage, Throwable pThrowable ) { | ||
super(pMessage, pThrowable); | ||
} | ||
|
||
public InvalidWgcFormatException( String pMessage ) { | ||
super(pMessage); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/WgcTag.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,42 @@ | ||
package de.wonejo.wuidebook.api.wgc; | ||
|
||
import de.wonejo.wuidebook.api.wgc.value.WgcTagValue; | ||
import de.wonejo.wuidebook.impl.wgc.WgcTagImpl; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public interface WgcTag { | ||
|
||
@NotNull | ||
static WgcTag createTag (String pKey, Map<ResourceLocation, Property<?>> pProperties) { | ||
return WgcTagImpl.createTag(pKey, pProperties); | ||
} | ||
|
||
<T> Property<T> getProperty ( ResourceLocation pKey ); | ||
boolean haveProperty ( ResourceLocation pKey ); | ||
|
||
String key (); | ||
Collection<? extends Property<?>> properties (); | ||
Set<ResourceLocation> propertiesKeySet (); | ||
|
||
interface Property<T> { | ||
|
||
@NotNull | ||
static <B> WgcTag.Property<B> createProperty ( ResourceLocation pKey, ResourceLocation pValueType, String pValue ) { | ||
return WgcTagImpl.PropertyImpl.createProperty(pKey, pValueType, pValue); | ||
} | ||
|
||
@NotNull | ||
static <B> WgcTag.Property<B> createProperty ( ResourceLocation pKey, WgcTagValue<B> pValue ) { | ||
return WgcTagImpl.PropertyImpl.createProperty(pKey, pValue); | ||
} | ||
|
||
ResourceLocation key (); | ||
WgcTagValue<T> value (); | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
XPlat/src/main/java/de/wonejo/wuidebook/api/wgc/value/NullWgcValue.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,19 @@ | ||
package de.wonejo.wuidebook.api.wgc.value; | ||
|
||
import de.wonejo.wuidebook.api.util.ResourceLocationUtils; | ||
|
||
public class NullWgcValue implements WgcTagValue<Object> { | ||
public static final WgcValueTagType<Object> TYPE = new WgcValueTagType<>(ResourceLocationUtils.wuidebook("wgc_null"), Object.class); | ||
|
||
public WgcTagValue<Object> copy() { | ||
return null; | ||
} | ||
|
||
public WgcValueTagType<Object> type() { | ||
return null; | ||
} | ||
|
||
public Object getValue() { | ||
return null; | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
XPlat/src/main/java/de/wonejo/wuidebook/impl/wgc/WgcTagImpl.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,89 @@ | ||
package de.wonejo.wuidebook.impl.wgc; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.collect.Maps; | ||
import de.wonejo.wuidebook.api.wgc.WgcTag; | ||
import de.wonejo.wuidebook.api.wgc.WgcValueTypeRegistry; | ||
import de.wonejo.wuidebook.api.wgc.value.WgcTagValue; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.*; | ||
|
||
public class WgcTagImpl implements WgcTag { | ||
|
||
@NotNull | ||
public static WgcTag createTag ( String pKey, Map<ResourceLocation, Property<?>> pProperties ) { | ||
return new WgcTagImpl(pKey, pProperties); | ||
} | ||
|
||
private final String key; | ||
private final Map<ResourceLocation, Property<?>> properties = Maps.newHashMap(); | ||
|
||
private WgcTagImpl ( String pKey, Map<ResourceLocation, Property<?>> pProperties ) { | ||
this.key = pKey; | ||
this.properties.putAll(pProperties); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> Property<T> getProperty(ResourceLocation pKey) { | ||
Property<T> prop = (Property<T>) this.properties.get(pKey); | ||
if (prop == null) | ||
throw new IllegalArgumentException("Property with key '" + pKey + "' not found."); | ||
return prop; | ||
} | ||
|
||
public boolean haveProperty(ResourceLocation pKey) { | ||
return this.properties.containsKey(pKey); | ||
} | ||
|
||
public String key() { | ||
return this.key; | ||
} | ||
|
||
public Collection<? extends Property<?>> properties() { | ||
return Collections.unmodifiableCollection(this.properties.values()); | ||
} | ||
|
||
public Set<ResourceLocation> propertiesKeySet() { | ||
return ImmutableSet.copyOf(this.properties.keySet()); | ||
} | ||
|
||
public static class PropertyImpl<T> implements WgcTag.Property<T> { | ||
|
||
@NotNull | ||
public static <B> WgcTag.Property<B> createProperty ( ResourceLocation pKey, ResourceLocation pValueType, String pValue ) { | ||
return new PropertyImpl<>(pKey, pValueType, pValue); | ||
} | ||
|
||
@NotNull | ||
public static <B> WgcTag.Property<B> createProperty ( ResourceLocation pKey, WgcTagValue<B> pValue ) { | ||
return new PropertyImpl<>(pKey, pValue); | ||
} | ||
|
||
private final ResourceLocation key; | ||
private final WgcTagValue<T> value; | ||
|
||
private PropertyImpl ( ResourceLocation pKey, ResourceLocation pValueType, String pValue ) { | ||
this.key = pKey; | ||
this.value = WgcValueTypeRegistry.get().createTagValue(pValueType, pValue); | ||
|
||
if (this.value == null) | ||
throw new IllegalArgumentException("Failed to create WgcTagValue for: " + pValueType); | ||
} | ||
|
||
private PropertyImpl ( ResourceLocation pKey, WgcTagValue<T> pValue ) { | ||
this.key = pKey; | ||
this.value = pValue; | ||
} | ||
|
||
public ResourceLocation key() { | ||
return this.key; | ||
} | ||
|
||
public WgcTagValue<T> value() { | ||
return this.value; | ||
} | ||
|
||
} | ||
} |