changed/removed terra originum shti
This commit is contained in:
13
src/main/java/com/smithy/faithful/util/CodecHelper.java
Normal file
13
src/main/java/com/smithy/faithful/util/CodecHelper.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.smithy.faithful.util;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class CodecHelper {
|
||||
|
||||
public static final Codec<ItemStack> STACK_OR_ITEM_NAME = Codec.either(ItemStack.CODEC, Registries.ITEM.getCodec()).xmap(either -> either.map(UnaryOperator.identity(), ItemStack::new), Either::left);
|
||||
}
|
||||
78
src/main/java/com/smithy/faithful/util/CustomDataTypes.java
Normal file
78
src/main/java/com/smithy/faithful/util/CustomDataTypes.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.smithy.faithful.util;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import io.github.apace100.calio.data.SerializableDataType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
public class CustomDataTypes {
|
||||
|
||||
public static final SerializableDataType<ItemStack> STACK_OR_ITEM_NAME = new SerializableDataType<>(
|
||||
ItemStack.class,
|
||||
PacketByteBuf::writeItemStack,
|
||||
PacketByteBuf::readItemStack,
|
||||
jsonElement -> CodecHelper.STACK_OR_ITEM_NAME.decode(JsonOps.INSTANCE, jsonElement).result().orElseThrow(() -> new JsonParseException("Could not parse ItemStack from JSON.")).getFirst()
|
||||
);
|
||||
|
||||
/*new SerializableDataType<>(ItemStack.class,
|
||||
PacketByteBuf::writeItem,
|
||||
PacketByteBuf::readItem,
|
||||
jsonElement -> CodecHelper.STACK_OR_ITEM_NAME.decode(JsonOps.INSTANCE, jsonElement).result().orElseThrow(() -> new JsonParseException("Could not parse ItemStack from JSON.")).getFirst()
|
||||
);*/
|
||||
|
||||
public static final SerializableDataType<OptionalBool> OPTIONAL_BOOL = new SerializableDataType<>(OptionalBool.class,
|
||||
PacketByteBuf::writeEnumConstant,
|
||||
buf -> buf.readEnumConstant(OptionalBool.class),
|
||||
jsonElement -> {
|
||||
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isBoolean()) {
|
||||
return OptionalBool.of(jsonElement.getAsBoolean());
|
||||
}
|
||||
return OptionalBool.DEFAULT;
|
||||
}
|
||||
);
|
||||
|
||||
public static final SerializableDataType<OptionalDouble> OPTIONAL_DOUBLE = new SerializableDataType<>(OptionalDouble.class,
|
||||
(buf, optionalDouble) -> {
|
||||
buf.writeBoolean(optionalDouble.isPresent());
|
||||
if (optionalDouble.isPresent()) {
|
||||
buf.writeDouble(optionalDouble.getAsDouble());
|
||||
}
|
||||
},
|
||||
buf -> {
|
||||
if (buf.readBoolean()) {
|
||||
return OptionalDouble.of(buf.readDouble());
|
||||
}
|
||||
return OptionalDouble.empty();
|
||||
},
|
||||
jsonElement -> {
|
||||
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
|
||||
return OptionalDouble.of(jsonElement.getAsDouble());
|
||||
}
|
||||
return OptionalDouble.empty();
|
||||
}
|
||||
);
|
||||
|
||||
public static final SerializableDataType<OptionalInt> OPTIONAL_INT = new SerializableDataType<>(OptionalInt.class,
|
||||
(buf, optionalInt) -> {
|
||||
buf.writeBoolean(optionalInt.isPresent());
|
||||
if (optionalInt.isPresent()) {
|
||||
buf.writeInt(optionalInt.getAsInt());
|
||||
}
|
||||
},
|
||||
buf -> {
|
||||
if (buf.readBoolean()) {
|
||||
return OptionalInt.of(buf.readInt());
|
||||
}
|
||||
return OptionalInt.empty();
|
||||
},
|
||||
jsonElement -> {
|
||||
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isNumber()) {
|
||||
return OptionalInt.of(jsonElement.getAsInt());
|
||||
}
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
);
|
||||
}
|
||||
38
src/main/java/com/smithy/faithful/util/OptionalBool.java
Normal file
38
src/main/java/com/smithy/faithful/util/OptionalBool.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.smithy.faithful.util;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
public enum OptionalBool {
|
||||
|
||||
TRUE,
|
||||
FALSE,
|
||||
DEFAULT;
|
||||
|
||||
public static OptionalBool of(Boolean value) {
|
||||
return value == null ? DEFAULT : value ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
public boolean isTrue() {
|
||||
return this == TRUE;
|
||||
}
|
||||
|
||||
public boolean orElse(boolean defaultValue) {
|
||||
return this == TRUE || (this == DEFAULT && defaultValue);
|
||||
}
|
||||
|
||||
public boolean orElseGet(BooleanSupplier defaultValue) {
|
||||
return this == TRUE || (this == DEFAULT && defaultValue.getAsBoolean());
|
||||
}
|
||||
|
||||
public Optional<Boolean> asOptional() {
|
||||
return this == DEFAULT ? Optional.empty() : Optional.of(isTrue());
|
||||
}
|
||||
|
||||
public static MapCodec<OptionalBool> codecFieldOf(String fieldName) {
|
||||
return Codec.BOOL.optionalFieldOf(fieldName).xmap(opt -> opt.map(aBoolean -> aBoolean ? TRUE : FALSE).orElse(DEFAULT), OptionalBool::asOptional);
|
||||
}
|
||||
}
|
||||
10
src/main/java/com/smithy/faithful/util/TerraHelper.java
Normal file
10
src/main/java/com/smithy/faithful/util/TerraHelper.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.smithy.faithful.util;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class TerraHelper {
|
||||
|
||||
public static boolean isWet(Entity entity) {
|
||||
return entity.isWet();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user