Skip to content

Commit

Permalink
Make byte codec for color (#15)
Browse files Browse the repository at this point in the history
cuz gravy is a bozo
  • Loading branch information
CodexAdrian authored Jun 8, 2024
1 parent 8981b6f commit a82a862
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.JsonOps;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.teamresourceful.bytecodecs.base.ByteCodec;
import com.teamresourceful.resourcefullib.common.utils.Scheduling;
import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.TextColor;
Expand All @@ -26,6 +27,15 @@ public class Color {
public static final Codec<Color> CODEC = Codec.PASSTHROUGH.comapFlatMap(Color::decodeColor, color -> new Dynamic<>(JsonOps.INSTANCE, new JsonPrimitive(color.value)));
public static final Color DEFAULT = defaultColor();
public static final Color RAINBOW = createRainbowColor();
public static final ByteCodec<Color> BYTE_CODEC = ByteCodec.BYTE.dispatch(aByte -> switch (aByte) {
case 0 -> ByteCodec.unit(DEFAULT);
case 1 -> ByteCodec.unit(RAINBOW);
default -> ByteCodec.INT.map(Color::new, Color::getValue);
}, color -> {
if (color.isDefault()) return (byte) 0;
if (color.isRainbow()) return (byte) 1;
return (byte) 2;
});

static {
ConstantColors.init();
Expand Down

0 comments on commit a82a862

Please sign in to comment.