Skip to content

Commit

Permalink
bacteria overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Thepigcat76 committed Dec 21, 2024
1 parent f6358ee commit e76feff
Show file tree
Hide file tree
Showing 32 changed files with 536 additions and 310 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 1.21.1 2024-12-19T15:16:06.7633778 Registries
4cc74761a420946768852a3c4e5fba64de831555 data/nautec/nautec/bacteria/cyanobacteria.json
2ceb7d9533a35c6cb05ba68915ecaf868def152a data/nautec/nautec/bacteria/empty.json
ce644e1811997ff67d2f7df856532017272a7b22 data/nautec/nautec/bacteria/halobacteria.json
36808ce13b558579e40af12e305adf733c501003 data/nautec/nautec/bacteria/methanogens.json
165e8d4b95ee84a6c951b35561ba6808bf60c49c data/nautec/nautec/bacteria/thermophiles.json
// 1.21.1 2024-12-21T13:29:07.948008452 Registries
731c134d2749f365fc9a6d44d8d6e400e77eec49 data/nautec/nautec/bacteria/cyanobacteria.json
6e0101d77b1f0382041425952ff4b8544733f2e2 data/nautec/nautec/bacteria/empty.json
81c72e6a3cfb78f800e627cdad79edbb044de4a1 data/nautec/nautec/bacteria/halobacteria.json
09d49475a6a9fffaf92674fc3f0e4df1f76ea94d data/nautec/nautec/bacteria/methanogens.json
f8693e008a409782cc34263ff0b2c2c61c99a3cc data/nautec/nautec/bacteria/thermophiles.json
d3949aab832fc1b72c2512c35586c2682dea4d4d data/nautec/worldgen/configured_feature/prismarine_sand_beach.json
e9f0c0ce377bc6f731c3b36673e845152a53327d data/nautec/worldgen/configured_feature/prismarine_sand_ocean.json
685d14b2486e0da05c931e69fe78236dd9523cbf data/nautec/worldgen/placed_feature/prismarine_sand_beach.json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-12-18T15:31:36.54862117 Item Models: nautec
// 1.21.1 2024-12-21T13:22:19.561016732 Item Models: nautec
53692692f57914fc54eb6ebf416ce1cb7789e57b assets/nautec/models/item/air_bottle.json
cc6ee3887ec6e0c53216dc681ac7b32b34182253 assets/nautec/models/item/anchor.json
2e336fce57acffa1d0eb621baa30a26f665b4924 assets/nautec/models/item/aquarine_steel_axe.json
Expand Down Expand Up @@ -26,6 +26,8 @@ a95dff0d56139e74443ee5069394ccbe31bc875a assets/nautec/models/item/atlantic_gold
f616877025b33a5d417689bd59cba3385b11e5c9 assets/nautec/models/item/augmentation_station_extension.json
8d57f0feda40d2aa883370a346a266cf9d149895 assets/nautec/models/item/bacterial_containment_shield.json
cd68bca3502f5a671aa5c4bbd828397047b19b8b assets/nautec/models/item/bio_reactor.json
53fad2021e8228bda58efa92544f377f7543832b assets/nautec/models/item/bio_reactor_part.json
cc14d169c8083ba22e2cf9eeae1842532d664950 assets/nautec/models/item/breaker.json
b1e3c9080ae5a0f78b06fa90f3c5da5b3805f842 assets/nautec/models/item/broken_whisk.json
cf1524c962ddbbf1cb5e8782d764e71888a03eb1 assets/nautec/models/item/brown_polymer.json
888a9dd92c350f3174e3cb52f714096944855bd5 assets/nautec/models/item/brown_polymer_block.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "nautec:block/bio_reactor_part"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "nautec:simple",
"resource": "minecraft:iron_ingot",
"stats": {
"colony_size": 0.0,
"type": "nautec:simple",
"color": -13434881,
"growth_rate": 0.0,
"lifespan": 0,
"mutation_resistance": 0.0,
"production_rate": 0.0,
"resource": "minecraft:iron_ingot"
"production_rate": 0.0
}
}
11 changes: 1 addition & 10 deletions src/generated/resources/data/nautec/nautec/bacteria/empty.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"type": "nautec:simple",
"stats": {
"colony_size": 0.0,
"color": 0,
"growth_rate": 0.0,
"lifespan": 0,
"mutation_resistance": 0.0,
"production_rate": 0.0,
"resource": "minecraft:air"
}
"type": "nautec:empty"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "nautec:simple",
"resource": "minecraft:gold_ingot",
"stats": {
"colony_size": 0.0,
"type": "nautec:simple",
"color": -6912,
"growth_rate": 0.0,
"lifespan": 0,
"mutation_resistance": 0.0,
"production_rate": 0.0,
"resource": "minecraft:gold_ingot"
"production_rate": 0.0
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "nautec:simple",
"resource": "minecraft:cooked_beef",
"stats": {
"colony_size": 0.0,
"type": "nautec:simple",
"color": -1328403,
"growth_rate": 0.0,
"lifespan": 0,
"mutation_resistance": 0.0,
"production_rate": 0.0,
"resource": "minecraft:cooked_beef"
"production_rate": 0.0
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"type": "nautec:simple",
"resource": "minecraft:lava_bucket",
"stats": {
"colony_size": 0.0,
"type": "nautec:simple",
"color": -65536,
"growth_rate": 0.0,
"lifespan": 0,
"mutation_resistance": 0.0,
"production_rate": 0.0,
"resource": "minecraft:lava_bucket"
"production_rate": 0.0
}
}
21 changes: 14 additions & 7 deletions src/main/java/com/portingdeadmods/nautec/NTRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,31 @@
import com.portingdeadmods.nautec.api.augments.AugmentSlot;
import com.portingdeadmods.nautec.api.augments.AugmentType;
import com.portingdeadmods.nautec.api.bacteria.BacteriaSerializer;
import com.portingdeadmods.nautec.api.bacteria.BacteriaStatsSerializer;
import com.portingdeadmods.nautec.api.multiblocks.Multiblock;
import com.portingdeadmods.nautec.api.bacteria.Bacteria;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
import net.neoforged.neoforge.registries.RegistryBuilder;

public final class NTRegistries {
private static final ResourceKey<Registry<AugmentType<?>>> AUGMENT_TYPE_KEY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "augment_type"));
public static final ResourceKey<Registry<AugmentSlot>> AUGMENT_SLOT_KEY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "augment_slot"));
private static final ResourceKey<Registry<Multiblock>> MULTIBLOCK_KEY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "multiblock"));
public static final ResourceKey<Registry<BacteriaSerializer<?>>> BACTERIA_SERIALIZER_KEY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "bacteria_serializer"));
public static final ResourceKey<Registry<Bacteria>> BACTERIA_KEY = ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "bacteria"));
private static final ResourceKey<Registry<AugmentType<?>>> AUGMENT_TYPE_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "augment_type"));
public static final ResourceKey<Registry<AugmentSlot>> AUGMENT_SLOT_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "augment_slot"));
private static final ResourceKey<Registry<Multiblock>> MULTIBLOCK_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "multiblock"));
public static final ResourceKey<Registry<BacteriaSerializer<?>>> BACTERIA_SERIALIZER_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "bacteria_serializer"));
public static final ResourceKey<Registry<BacteriaStatsSerializer<?>>> BACTERIA_STATS_SERIALIZER_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "bacteria_stats_serializer"));
public static final ResourceKey<Registry<Bacteria>> BACTERIA_KEY =
ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "bacteria"));

public static final Registry<AugmentType<?>> AUGMENT_TYPE = new RegistryBuilder<>(AUGMENT_TYPE_KEY).create();
public static final Registry<AugmentSlot> AUGMENT_SLOT = new RegistryBuilder<>(AUGMENT_SLOT_KEY).create();
public static final Registry<Multiblock> MULTIBLOCK = new RegistryBuilder<>(MULTIBLOCK_KEY).create();
public static final Registry<BacteriaSerializer<?>> BACTERIA_SERIALIZER = new RegistryBuilder<>(BACTERIA_SERIALIZER_KEY).create();
public static final Registry<BacteriaStatsSerializer<?>> BACTERIA_STATS_SERIALIZER = new RegistryBuilder<>(BACTERIA_STATS_SERIALIZER_KEY).create();
}
2 changes: 2 additions & 0 deletions src/main/java/com/portingdeadmods/nautec/Nautec.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public Nautec(IEventBus modEventBus, ModContainer modContainer) {
event.register(NTRegistries.AUGMENT_SLOT);
event.register(NTRegistries.AUGMENT_TYPE);
event.register(NTRegistries.BACTERIA_SERIALIZER);
event.register(NTRegistries.BACTERIA_STATS_SERIALIZER);
});

modEventBus.addListener(DataPackRegistryEvent.NewRegistry.class, event -> {
Expand All @@ -82,6 +83,7 @@ public Nautec(IEventBus modEventBus, ModContainer modContainer) {
NTStructures.STRUCTURES.register(modEventBus);
NTLootModifier.LOOT_MODIFIERS.register(modEventBus);
NTBacteriaSerializers.SERIALIZERS.register(modEventBus);
NTBacteriaStatsSerializers.SERIALIZERS.register(modEventBus);

NTFluids.HELPER.register(modEventBus);

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/portingdeadmods/nautec/NautecClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.entity.ThrownTridentRenderer;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import net.minecraft.util.FastColor;
Expand Down Expand Up @@ -225,8 +226,9 @@ private void onFMLClientSetupEvent(final FMLClientSetupEvent event) {

private void registerColorHandlers(RegisterColorHandlersEvent.Item event) {
event.register((stack, layer) -> {
Bacteria bacteria = BacteriaHelper.getBacteria(Minecraft.getInstance().level.registryAccess(), stack.get(NTDataComponents.BACTERIA).bacteria());
return layer == 1 ? bacteria.stats().color() : -1;
ResourceKey<Bacteria> bacteriaType = stack.get(NTDataComponents.BACTERIA).bacteriaInstance().getBacteria();
Bacteria bacteria = BacteriaHelper.getBacteria(Minecraft.getInstance().level.registryAccess(), bacteriaType);
return layer == 1 ? bacteria.initialStats().color() : -1;
}, NTItems.PETRI_DISH);
event.register(new DynamicFluidContainerModel.Colors(), NTFluids.SALT_WATER.getBucket());
}
Expand Down
51 changes: 38 additions & 13 deletions src/main/java/com/portingdeadmods/nautec/api/bacteria/Bacteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

import com.mojang.serialization.Codec;
import com.portingdeadmods.nautec.NTRegistries;
import com.portingdeadmods.nautec.content.bacteria.BacteriaStats;
import com.portingdeadmods.nautec.content.bacteria.SimpleBacteria;
import com.portingdeadmods.nautec.utils.codec.CodecUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Item;

/**
Bacteria! We begin with only one!
Bacteria! Two's what we then become!
Bacteria! Each of us becomes two more!
Bacteria! We are stronger than before!
Bacteria! We keep growing at this rate!
Bacteria! No longer shall we wait!
Bacteria! The plan now unfolds!
Bacteria! We will take over the world!
* Bacteria! We begin with only one!
* Bacteria! Two's what we then become!
* Bacteria! Each of us becomes two more!
* Bacteria! We are stronger than before!
* Bacteria! We keep growing at this rate!
* Bacteria! No longer shall we wait!
* Bacteria! The plan now unfolds!
* Bacteria! We will take over the world!
*/
public interface Bacteria {
Codec<ResourceKey<Bacteria>> BACTERIA_TYPE_CODEC = ResourceKey.codec(NTRegistries.BACTERIA_KEY);
Expand All @@ -29,7 +27,34 @@ public interface Bacteria {
Codec<Bacteria> CODEC = NTRegistries.BACTERIA_SERIALIZER.byNameCodec().dispatch(Bacteria::getSerializer, BacteriaSerializer::mapCodec);
StreamCodec<RegistryFriendlyByteBuf, Bacteria> STREAM_CODEC = ByteBufCodecs.registry(NTRegistries.BACTERIA_SERIALIZER_KEY).dispatch(Bacteria::getSerializer, BacteriaSerializer::streamCodec);

BaseBacteriaStats stats();
Resource resource();

BacteriaStats initialStats();

BacteriaSerializer<?> getSerializer();

interface Resource {
Codec<? extends Resource> codec();

StreamCodec<ByteBuf, ? extends Resource> streamCodec();

record ItemResource(Item item) implements Resource {
public static final Codec<ItemResource> CODEC = CodecUtils.ITEM_CODEC.xmap(ItemResource::new, ItemResource::item);
public static final StreamCodec<ByteBuf, ItemResource> STREAM_CODEC = CodecUtils.ITEM_STREAM_CODEC.map(ItemResource::new, ItemResource::item);

@Override
public Codec<ItemResource> codec() {
return CODEC;
}

@Override
public StreamCodec<ByteBuf, ItemResource> streamCodec() {
return STREAM_CODEC;
}
}
}

interface Builder<T extends Bacteria> {
T build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.portingdeadmods.nautec.api.bacteria;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.portingdeadmods.nautec.content.bacteria.SimpleBacteriaStats;
import com.portingdeadmods.nautec.registries.NTBacterias;
import com.portingdeadmods.nautec.utils.BacteriaHelper;
import net.minecraft.core.HolderLookup;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceKey;

public final class BacteriaInstance {
public static final BacteriaInstance EMPTY = new BacteriaInstance(NTBacterias.EMPTY, SimpleBacteriaStats.EMPTY);
public static final Codec<BacteriaInstance> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Bacteria.BACTERIA_TYPE_CODEC.fieldOf("bacteria").forGetter(BacteriaInstance::getBacteria),
Codec.LONG.fieldOf("amount").forGetter(BacteriaInstance::getAmount),
BacteriaStats.CODEC.fieldOf("stats").forGetter(BacteriaInstance::getStats)
).apply(instance, BacteriaInstance::new));
public static final StreamCodec<RegistryFriendlyByteBuf, BacteriaInstance> STREAM_CODEC = StreamCodec.composite(
Bacteria.BACTERIA_TYPE_STREAM_CODEC,
BacteriaInstance::getBacteria,
ByteBufCodecs.VAR_LONG,
BacteriaInstance::getAmount,
BacteriaStats.STREAM_CODEC,
BacteriaInstance::getStats,
BacteriaInstance::new
);

private final ResourceKey<Bacteria> bacteria;
private long amount;
private BacteriaStats stats;

public BacteriaInstance(ResourceKey<Bacteria> bacteria, HolderLookup.Provider lookup) {
this(bacteria, 1, BacteriaHelper.getBacteria(lookup, bacteria).initialStats());
}

public BacteriaInstance(ResourceKey<Bacteria> bacteria, BacteriaStats stats) {
this(bacteria, 1, stats);
}

public BacteriaInstance(ResourceKey<Bacteria> bacteria, long amount, BacteriaStats stats) {
this.bacteria = bacteria;
this.amount = amount;
this.stats = stats;
}

public void setAmount(long amount) {
this.amount = amount;
}

public long getAmount() {
return this.amount;
}

public ResourceKey<Bacteria> getBacteria() {
return bacteria;
}

public void setStats(BacteriaStats stats) {
this.stats = stats;
}

public BacteriaStats getStats() {
return this.stats;
}

public BacteriaInstance copy() {
return new BacteriaInstance(this.bacteria, amount, this.stats.copy());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.portingdeadmods.nautec.api.bacteria;

import com.mojang.serialization.Codec;
import com.portingdeadmods.nautec.NTRegistries;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

import java.util.List;

public interface BacteriaStats {
Codec<BacteriaStats> CODEC =
NTRegistries.BACTERIA_STATS_SERIALIZER.byNameCodec().dispatch(BacteriaStats::getSerializer, BacteriaStatsSerializer::mapCodec);
StreamCodec<RegistryFriendlyByteBuf, BacteriaStats> STREAM_CODEC =
ByteBufCodecs.registry(NTRegistries.BACTERIA_STATS_SERIALIZER_KEY).dispatch(BacteriaStats::getSerializer, BacteriaStatsSerializer::streamCodec);


float growthRate();

float mutationResistance();

float productionRate();

int lifespan();

int color();

BacteriaStats copy();

List<Component> statsTooltip();

BacteriaStatsSerializer<?> getSerializer();

// Mutator
BacteriaStats rollGrowthRate();
BacteriaStats rollMutationResistance();
BacteriaStats rollProductionRate();
BacteriaStats rollLifespan();
BacteriaStats rollStats();

// Incubator
BacteriaStats grow();
BacteriaStats shrink();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.portingdeadmods.nautec.api.bacteria;

import com.mojang.serialization.MapCodec;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;

public interface BacteriaStatsSerializer<T extends BacteriaStats> {
MapCodec<T> mapCodec();

StreamCodec<RegistryFriendlyByteBuf, T> streamCodec();
}
Loading

0 comments on commit e76feff

Please sign in to comment.