Skip to content

Commit

Permalink
Color :3
Browse files Browse the repository at this point in the history
  • Loading branch information
ReclipseTheOne committed Dec 15, 2024
1 parent 879abbe commit 16685c2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/java/com/portingdeadmods/nautec/bacteria/Bacteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,32 @@ public interface Bacteria {
float mutationResistance();
float productionRate();
int lifespan();
int color();

default byte getAlpha() {
return (byte) ((color() >> 24) & 0xFF);
}

default byte getRed() {
return (byte) ((color() >> 16) & 0xFF);
}

default byte getGreen() {
return (byte) ((color() >> 8) & 0xFF);
}

default byte getBlue() {
return (byte) (color() & 0xFF);
}

Codec<Bacteria> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
CodecUtils.ITEM_CODEC.fieldOf("type").forGetter(Bacteria::type),
Codec.FLOAT.fieldOf("growth_rate").forGetter(Bacteria::growthRate),
Codec.FLOAT.fieldOf("mutation_resistance").forGetter(Bacteria::mutationResistance),
Codec.FLOAT.fieldOf("production_rate").forGetter(Bacteria::productionRate),
Codec.INT.fieldOf("lifespan").forGetter(Bacteria::lifespan)
Codec.INT.fieldOf("lifespan").forGetter(Bacteria::lifespan),
Codec.INT.fieldOf("color").forGetter(Bacteria::color)
).apply(instance, BacteriaImpl::new)
);

Expand All @@ -47,6 +65,8 @@ public interface Bacteria {
Bacteria::productionRate,
ByteBufCodecs.INT,
Bacteria::lifespan,
ByteBufCodecs.INT,
Bacteria::color,
BacteriaImpl::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ public record BacteriaImpl(
float growthRate,
float mutationResistance,
float productionRate,
int lifespan) implements Bacteria {
int lifespan,
int color) implements Bacteria {

@Override
public byte getAlpha() {
return (byte) ((color >> 24) & 0xFF);
}

@Override
public byte getRed() {
return (byte) ((color >> 16) & 0xFF);
}

@Override
public byte getGreen() {
return (byte) ((color >> 8) & 0xFF);
}

@Override
public byte getBlue() {
return (byte) (color & 0xFF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public float productionRate() {
public int lifespan() {
return 0;
}

@Override
public int color() {
return 0;
}
}, 0);
public static final Codec<ComponentBacteriaStorage> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Bacteria.CODEC.fieldOf("bacteriaType").forGetter(ComponentBacteriaStorage::bacteria),
Expand Down

0 comments on commit 16685c2

Please sign in to comment.