Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows throwing the proper exception type in the constructor for throwing constructors since fields know whether they are in JSON or buffers (constructors don't)
- Loading branch information
1 parent
d51ba38
commit 60b233c
Showing
2 changed files
with
31 additions
and
0 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
27 changes: 27 additions & 0 deletions
27
src/main/java/slimeknights/mantle/data/loadable/field/ConstantField.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 slimeknights.mantle.data.loadable.field; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
/** Record field that always returns the same value, used mainly to pass a different object in JSON vs buffer parsing */ | ||
public record ConstantField<T>(T fromJson, T fromBuffer) implements LoadableField<T,Object> { | ||
public ConstantField(T value) { | ||
this(value, value); | ||
} | ||
|
||
@Override | ||
public T get(JsonObject json) { | ||
return fromJson; | ||
} | ||
|
||
@Override | ||
public T decode(FriendlyByteBuf buffer) { | ||
return fromBuffer; | ||
} | ||
|
||
@Override | ||
public void serialize(Object parent, JsonObject json) {} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer, Object parent) {} | ||
} |