did #440, SerDer of Vec3Iotas as CompoundTags.
This commit is contained in:
parent
d51fe053e3
commit
c4c2825f3d
|
@ -3,6 +3,7 @@ package at.petrak.hexcasting.api.casting.iota;
|
|||
import at.petrak.hexcasting.api.utils.HexUtils;
|
||||
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.LongArrayTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
@ -62,8 +63,12 @@ public class Vec3Iota extends Iota {
|
|||
};
|
||||
|
||||
public static Vec3Iota deserialize(Tag tag) throws IllegalArgumentException {
|
||||
var lat = HexUtils.downcast(tag, LongArrayTag.TYPE);
|
||||
var vec = HexUtils.vecFromNBT(lat.getAsLongArray());
|
||||
Vec3 vec;
|
||||
if (tag.getType() == LongArrayTag.TYPE) {
|
||||
var lat = HexUtils.downcast(tag, LongArrayTag.TYPE);
|
||||
vec = HexUtils.vecFromNBT(lat.getAsLongArray());
|
||||
} else
|
||||
vec = HexUtils.vecFromNBT(HexUtils.downcast(tag, CompoundTag.TYPE));
|
||||
return new Vec3Iota(vec);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,13 @@ import kotlin.reflect.KProperty
|
|||
const val TAU = Math.PI * 2.0
|
||||
const val SQRT_3 = 1.7320508f
|
||||
|
||||
fun Vec3.serializeToNBT(): LongArrayTag =
|
||||
LongArrayTag(longArrayOf(this.x.toRawBits(), this.y.toRawBits(), this.z.toRawBits()))
|
||||
fun Vec3.serializeToNBT(): CompoundTag {
|
||||
val tag = CompoundTag()
|
||||
tag.putDouble("x", this.x)
|
||||
tag.putDouble("y", this.x)
|
||||
tag.putDouble("z", this.x)
|
||||
return tag
|
||||
}
|
||||
|
||||
fun vecFromNBT(tag: LongArray): Vec3 = if (tag.size != 3) Vec3.ZERO else
|
||||
Vec3(
|
||||
|
@ -39,6 +44,12 @@ fun vecFromNBT(tag: LongArray): Vec3 = if (tag.size != 3) Vec3.ZERO else
|
|||
Double.fromBits(tag[1]),
|
||||
Double.fromBits(tag[2])
|
||||
)
|
||||
fun vecFromNBT(tag: CompoundTag): Vec3 {
|
||||
return if (!tag.contains("x") || !tag.contains("y") || !tag.contains("z"))
|
||||
Vec3.ZERO
|
||||
else
|
||||
Vec3(tag.getDouble("x"), tag.getDouble("y"), tag.getDouble("z"))
|
||||
}
|
||||
|
||||
fun Vec2.serializeToNBT(): LongArrayTag =
|
||||
LongArrayTag(longArrayOf(this.x.toDouble().toRawBits(), this.y.toDouble().toRawBits()))
|
||||
|
|
Loading…
Reference in a new issue