Skip to content

Commit

Permalink
move FloatingLong codec into FL class
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Nov 5, 2023
1 parent 0eeb087 commit 8c60b1c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
14 changes: 0 additions & 14 deletions src/api/java/mekanism/api/SerializerHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.PrimitiveCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Optional;
import java.util.function.Function;
Expand Down Expand Up @@ -91,18 +89,6 @@ private SerializerHelper() {
case SLURRY -> SlurryStack.CODEC;
});

public static final Codec<FloatingLong> FLOATING_LONG_CODEC = new PrimitiveCodec<FloatingLong>() {
@Override
public <T> DataResult<FloatingLong> read(DynamicOps<T> ops, T input) {
return ops.getNumberValue(input).map(number -> FloatingLong.fromNumber(number, true));
}

@Override
public <T> T write(DynamicOps<T> ops, FloatingLong value) {
return ops.createNumeric(value);
}
};

/**
* Deserializes a FloatingLong that is stored in a specific key in a Json Object.
*
Expand Down
15 changes: 15 additions & 0 deletions src/api/java/mekanism/api/math/FloatingLong.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package mekanism.api.math;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.PrimitiveCodec;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
Expand All @@ -16,6 +20,17 @@
@NothingNullByDefault
public class FloatingLong extends Number implements Comparable<FloatingLong> {

public static final Codec<FloatingLong> FLOATING_LONG_CODEC = new PrimitiveCodec<FloatingLong>() {
@Override
public <T> DataResult<FloatingLong> read(DynamicOps<T> ops, T input) {
return ops.getNumberValue(input).map(number -> fromNumber(number, true));
}

@Override
public <T> T write(DynamicOps<T> ops, FloatingLong value) {
return ops.createNumeric(value);
}
};
private static final DecimalFormat df = new DecimalFormat("0.0000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));

//TODO: Eventually we should define a way of doing a set of operations all at once, and outputting a new value
Expand Down

0 comments on commit 8c60b1c

Please sign in to comment.