From f0e7e077c82569899ec853bb98fa523c0d4d3c0a Mon Sep 17 00:00:00 2001 From: ktpatient Date: Sun, 22 Dec 2024 22:17:18 +0000 Subject: [PATCH 1/4] Add Creative Energy (FE) Source Block --- .../CreativeEnergySourceBlockEntity.java | 45 +++++++++++++++++++ .../blocks/CreativeEnergySourceBlock.java | 41 +++++++++++++++++ .../nautec/registries/NTBlockEntityTypes.java | 3 ++ .../nautec/registries/NTBlocks.java | 2 + 4 files changed, 91 insertions(+) create mode 100644 src/main/java/com/portingdeadmods/nautec/content/blockentities/CreativeEnergySourceBlockEntity.java create mode 100644 src/main/java/com/portingdeadmods/nautec/content/blocks/CreativeEnergySourceBlock.java diff --git a/src/main/java/com/portingdeadmods/nautec/content/blockentities/CreativeEnergySourceBlockEntity.java b/src/main/java/com/portingdeadmods/nautec/content/blockentities/CreativeEnergySourceBlockEntity.java new file mode 100644 index 0000000..140206c --- /dev/null +++ b/src/main/java/com/portingdeadmods/nautec/content/blockentities/CreativeEnergySourceBlockEntity.java @@ -0,0 +1,45 @@ +package com.portingdeadmods.nautec.content.blockentities; + +import com.portingdeadmods.nautec.registries.NTBlockEntityTypes; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.energy.IEnergyStorage; + +public class CreativeEnergySourceBlockEntity extends BlockEntity implements IEnergyStorage { + private static final int MAX_ENERGY = Integer.MAX_VALUE; + + public CreativeEnergySourceBlockEntity(BlockPos pos, BlockState blockState) { + super(NTBlockEntityTypes.CREATIVE_ENERGY_SOURCE.get(), pos, blockState); + } + + @Override + public int receiveEnergy(int toReceive, boolean simulate) { + return 0; + } + + @Override + public int extractEnergy(int toExtract, boolean simulate) { + return toExtract; + } + + @Override + public int getEnergyStored() { + return MAX_ENERGY; + } + + @Override + public int getMaxEnergyStored() { + return MAX_ENERGY; + } + + @Override + public boolean canExtract() { + return true; + } + + @Override + public boolean canReceive() { + return false; + } +} diff --git a/src/main/java/com/portingdeadmods/nautec/content/blocks/CreativeEnergySourceBlock.java b/src/main/java/com/portingdeadmods/nautec/content/blocks/CreativeEnergySourceBlock.java new file mode 100644 index 0000000..b090fd1 --- /dev/null +++ b/src/main/java/com/portingdeadmods/nautec/content/blocks/CreativeEnergySourceBlock.java @@ -0,0 +1,41 @@ +package com.portingdeadmods.nautec.content.blocks; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +public class CreativeEnergySourceBlock extends Block implements EntityBlock { + public CreativeEnergySourceBlock(Properties properties) { + super(properties); + } + + @Override + public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return null; + } + + @Override + protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) { + super.onPlace(state, level, pos, oldState, movedByPiston); + level.scheduleTick(pos, this, 1); + } + + @Override + protected void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { + super.tick(state, level, pos, random); + level.scheduleTick(pos,this,1); + } + + @Override + protected boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, int param) { + super.triggerEvent(state, level, pos, id, param); + BlockEntity be = level.getBlockEntity(pos); + return be != null && be.triggerEvent(id, param); + } +} diff --git a/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java b/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java index 4393ade..136d2fd 100644 --- a/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java +++ b/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java @@ -71,6 +71,9 @@ public final class NTBlockEntityTypes { public static final Supplier> CREATIVE_POWER_SOURCE = BLOCK_ENTITIES.register("creative_power_source", () -> BlockEntityType.Builder.of(CreativePowerSourceBlockEntity::new, NTBlocks.CREATIVE_POWER_SOURCE.get()).build(null)); + public static final Supplier> CREATIVE_ENERGY_SOURCE = BLOCK_ENTITIES.register("creative_energy_source", + () -> BlockEntityType.Builder.of(CreativeEnergySourceBlockEntity::new, + NTBlocks.CREATIVE_ENERGY_SOURCE.get()).build(null)); public static final Supplier> CHARGER = BLOCK_ENTITIES.register("charger", () -> BlockEntityType.Builder.of(ChargerBlockEntity::new, NTBlocks.CHARGER.get()).build(null)); diff --git a/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java b/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java index 520fd49..c1668d5 100644 --- a/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java +++ b/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java @@ -112,6 +112,8 @@ public final class NTBlocks { public static final DeferredBlock CREATIVE_POWER_SOURCE = registerBlockAndItem("creative_power_source", CreativePowerSourceBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), false, true); + public static final DeferredBlock CREATIVE_ENERGY_SOURCE = registerBlockAndItem("creative_energy_source", CreativeEnergySourceBlock::new, + BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), false, true); private static DeferredBlock registerBlockAndItem(String name, Function blockConstructor, BlockBehaviour.Properties properties) { return registerBlockAndItem(name, blockConstructor, properties, true, true); From b2f967aa28f974a9a6c4fad19aca4206d5227f7f Mon Sep 17 00:00:00 2001 From: ktpatient Date: Sun, 22 Dec 2024 22:33:58 +0000 Subject: [PATCH 2/4] Energy Converter --- .../EnergyConverterBlockEntity.java | 92 +++++++++++++++++++ .../content/blocks/EnergyConverterBlock.java | 20 ++++ .../nautec/registries/NTBlockEntityTypes.java | 3 + .../nautec/registries/NTBlocks.java | 2 + 4 files changed, 117 insertions(+) create mode 100644 src/main/java/com/portingdeadmods/nautec/content/blockentities/EnergyConverterBlockEntity.java create mode 100644 src/main/java/com/portingdeadmods/nautec/content/blocks/EnergyConverterBlock.java diff --git a/src/main/java/com/portingdeadmods/nautec/content/blockentities/EnergyConverterBlockEntity.java b/src/main/java/com/portingdeadmods/nautec/content/blockentities/EnergyConverterBlockEntity.java new file mode 100644 index 0000000..98afe9a --- /dev/null +++ b/src/main/java/com/portingdeadmods/nautec/content/blockentities/EnergyConverterBlockEntity.java @@ -0,0 +1,92 @@ +package com.portingdeadmods.nautec.content.blockentities; + +import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity; +import com.portingdeadmods.nautec.capabilities.IOActions; +import com.portingdeadmods.nautec.registries.NTBlockEntityTypes; +import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.objects.ObjectSet; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.capabilities.BlockCapability; +import net.neoforged.neoforge.energy.IEnergyStorage; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +public class EnergyConverterBlockEntity extends LaserBlockEntity implements IEnergyStorage { + private static final int FE_CONVERSION_RATE = 100; + private int feStored = 0; + private static final int MAX_FE = 100000; + + public EnergyConverterBlockEntity(BlockPos blockPos, BlockState blockState) { + super(NTBlockEntityTypes.ENERGY_CONVERTER.get(), blockPos, blockState); + } + + @Override + public ObjectSet getLaserInputs() { + return ObjectSet.of(); + } + + @Override + public ObjectSet getLaserOutputs() { + return ObjectSet.of(Direction.values()); + } + + @Override + public Map> getSidedInteractions(BlockCapability capability) { + return Map.of(); + } + + @Override + public void commonTick() { + if (!level.isClientSide) { + Direction[] directions = Direction.values(); + for (Direction direction : directions) { + BlockPos pos = worldPosition.relative(direction); + if (level.getBlockEntity(pos) instanceof LaserBlockEntity laserBlockEntity) { + if (laserBlockEntity.getLaserInputs().contains(direction.getOpposite())) { + int energyToConvert = Math.min(FE_CONVERSION_RATE, feStored); + if (energyToConvert > 0) { + transmitPower(energyToConvert); + feStored -= energyToConvert; + } + } + } + } + } + } + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + int energyReceived = Math.min(MAX_FE - feStored, maxReceive); + if (!simulate) { + feStored += energyReceived; + } + return energyReceived; + } + + @Override + public int extractEnergy(int maxExtract, boolean simulate) { + return 0; + } + + @Override + public int getEnergyStored() { + return feStored; + } + + @Override + public int getMaxEnergyStored() { + return MAX_FE; + } + + @Override + public boolean canExtract() { + return false; + } + + @Override + public boolean canReceive() { + return true; + } +} diff --git a/src/main/java/com/portingdeadmods/nautec/content/blocks/EnergyConverterBlock.java b/src/main/java/com/portingdeadmods/nautec/content/blocks/EnergyConverterBlock.java new file mode 100644 index 0000000..5c77886 --- /dev/null +++ b/src/main/java/com/portingdeadmods/nautec/content/blocks/EnergyConverterBlock.java @@ -0,0 +1,20 @@ +package com.portingdeadmods.nautec.content.blocks; + +import com.portingdeadmods.nautec.content.blockentities.EnergyConverterBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +public class EnergyConverterBlock extends Block implements EntityBlock { + public EnergyConverterBlock(Properties properties) { + super(properties); + } + + @Override + public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) { + return new EnergyConverterBlockEntity(pos,state); + } +} diff --git a/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java b/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java index 136d2fd..91ae690 100644 --- a/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java +++ b/src/main/java/com/portingdeadmods/nautec/registries/NTBlockEntityTypes.java @@ -74,6 +74,9 @@ public final class NTBlockEntityTypes { public static final Supplier> CREATIVE_ENERGY_SOURCE = BLOCK_ENTITIES.register("creative_energy_source", () -> BlockEntityType.Builder.of(CreativeEnergySourceBlockEntity::new, NTBlocks.CREATIVE_ENERGY_SOURCE.get()).build(null)); + public static final Supplier> ENERGY_CONVERTER = BLOCK_ENTITIES.register("energy_converter", + () -> BlockEntityType.Builder.of(EnergyConverterBlockEntity::new, + NTBlocks.ENERGY_CONVERTER.get()).build(null)); public static final Supplier> CHARGER = BLOCK_ENTITIES.register("charger", () -> BlockEntityType.Builder.of(ChargerBlockEntity::new, NTBlocks.CHARGER.get()).build(null)); diff --git a/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java b/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java index c1668d5..e9f4cf9 100644 --- a/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java +++ b/src/main/java/com/portingdeadmods/nautec/registries/NTBlocks.java @@ -114,6 +114,8 @@ public final class NTBlocks { BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), false, true); public static final DeferredBlock CREATIVE_ENERGY_SOURCE = registerBlockAndItem("creative_energy_source", CreativeEnergySourceBlock::new, BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), false, true); + public static final DeferredBlock ENERGY_CONVERTER = registerBlockAndItem("energy_converter", EnergyConverterBlock::new, + BlockBehaviour.Properties.ofFullCopy(Blocks.IRON_BLOCK), false, true); private static DeferredBlock registerBlockAndItem(String name, Function blockConstructor, BlockBehaviour.Properties properties) { return registerBlockAndItem(name, blockConstructor, properties, true, true); From b04aec9019c1e5b8d752f4b2e4a79a6ce4cb4f72 Mon Sep 17 00:00:00 2001 From: Reclipse <17797013+ReclipseTheOne@users.noreply.github.com> Date: Mon, 23 Dec 2024 04:18:16 +0200 Subject: [PATCH 3/4] Mutator's functionality is doneeeeeeeeeeeeeeeeeeeeee (need model and we done :>) --- .../portingdeadmods/nautec/NautecClient.java | 1 + .../nautec/api/bacteria/BacteriaStats.java | 1 + .../nautec/client/screen/MutatorScreen.java | 6 ++- .../content/bacteria/SimpleBacteriaStats.java | 53 ++++++++++++++++++- .../blockentities/MutatorBlockEntity.java | 17 +++--- .../nautec/content/items/PetriDishItem.java | 31 +++++++---- .../nautec/utils/BacteriaHelper.java | 5 ++ .../nautec/utils/ComponentUtils.java | 23 +++++++- .../nautec/utils/MathUtils.java | 4 ++ 9 files changed, 118 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/portingdeadmods/nautec/NautecClient.java b/src/main/java/com/portingdeadmods/nautec/NautecClient.java index e42d8a3..78b6064 100644 --- a/src/main/java/com/portingdeadmods/nautec/NautecClient.java +++ b/src/main/java/com/portingdeadmods/nautec/NautecClient.java @@ -163,6 +163,7 @@ private void registerBERenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerBlockEntityRenderer(NTBlockEntityTypes.ANCHOR.get(), AnchorBERenderer::new); event.registerBlockEntityRenderer(NTBlockEntityTypes.BACTERIAL_ANALYZER.get(), BacterialAnalyzerBERenderer::new); event.registerBlockEntityRenderer(NTBlockEntityTypes.FISHING_STATION.get(), FishingStationBERenderer::new); + AugmentLayerRenderer.registerRenderer(NTAugments.DOLPHIN_FIN.get(), ctx -> new SimpleAugmentRenderer<>(DolphinFinModel::new, DolphinFinModel.LAYER_LOCATION, DolphinFinModel.MATERIAL, true, ctx)); AugmentLayerRenderer.registerRenderer(NTAugments.GUARDIAN_EYE.get(), GuardianEyeRenderer::new); diff --git a/src/main/java/com/portingdeadmods/nautec/api/bacteria/BacteriaStats.java b/src/main/java/com/portingdeadmods/nautec/api/bacteria/BacteriaStats.java index 550c23f..7512ed9 100644 --- a/src/main/java/com/portingdeadmods/nautec/api/bacteria/BacteriaStats.java +++ b/src/main/java/com/portingdeadmods/nautec/api/bacteria/BacteriaStats.java @@ -29,6 +29,7 @@ public interface BacteriaStats { BacteriaStats copy(); List statsTooltip(); + List statsTooltipWithMutatorValues(); BacteriaStatsSerializer getSerializer(); diff --git a/src/main/java/com/portingdeadmods/nautec/client/screen/MutatorScreen.java b/src/main/java/com/portingdeadmods/nautec/client/screen/MutatorScreen.java index 41a36ac..ae687f1 100644 --- a/src/main/java/com/portingdeadmods/nautec/client/screen/MutatorScreen.java +++ b/src/main/java/com/portingdeadmods/nautec/client/screen/MutatorScreen.java @@ -1,5 +1,6 @@ package com.portingdeadmods.nautec.client.screen; +import com.portingdeadmods.nautec.NTConfig; import com.portingdeadmods.nautec.Nautec; import com.portingdeadmods.nautec.api.client.screen.NTAbstractContainerScreen; import com.portingdeadmods.nautec.api.menu.NTAbstractContainerMenu; @@ -29,8 +30,9 @@ protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mo int progress = menu.blockEntity.getProgress(); - int j1 = Mth.ceil(((float) progress / BacterialAnalyzerBlockEntity.MAX_PROGRESS) * 72.0F); - guiGraphics.blitSprite(PROGRESS_ARROW, 72, 24, 0, 0, i + 76, j + 29, j1, 24); + int j1 = Mth.ceil(((float) progress / NTConfig.mutatorCraftingSpeed) * 79.0F); + + guiGraphics.blitSprite(PROGRESS_ARROW, 79, 24, 0, 0, i + 47, j + 22, j1, 24); } @Override diff --git a/src/main/java/com/portingdeadmods/nautec/content/bacteria/SimpleBacteriaStats.java b/src/main/java/com/portingdeadmods/nautec/content/bacteria/SimpleBacteriaStats.java index 02522b1..6d26221 100644 --- a/src/main/java/com/portingdeadmods/nautec/content/bacteria/SimpleBacteriaStats.java +++ b/src/main/java/com/portingdeadmods/nautec/content/bacteria/SimpleBacteriaStats.java @@ -3,12 +3,16 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import com.portingdeadmods.nautec.Nautec; import com.portingdeadmods.nautec.api.bacteria.BacteriaStats; import com.portingdeadmods.nautec.api.bacteria.BacteriaStatsSerializer; import com.portingdeadmods.nautec.utils.ComponentUtils; +import com.portingdeadmods.nautec.utils.MathUtils; import com.portingdeadmods.nautec.utils.RNGUtils; +import net.minecraft.ChatFormatting; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; @@ -60,6 +64,46 @@ public List statsTooltip() { ); } + @Override + public List statsTooltipWithMutatorValues() { + final MutableComponent arrow = ComponentUtils.colored(" -> ", ChatFormatting.YELLOW); + + return List.of( + ComponentUtils.countableStatShow("Growth Rate", growthRate, bacteriaGrowthRateCap) + .append(arrow) + .append(ComponentUtils.colored("[", ChatFormatting.GREEN)) + .append(ComponentUtils.statRange( + MathUtils.roundToPrecision(growthRate + (-growthRate / (10 * (1 + mutationResistance))), 2), + MathUtils.roundToPrecision(growthRate + (growthRate / (10 * (1 + mutationResistance))), 2), + bacteriaGrowthRateCap)) + .append(ComponentUtils.colored("]", ChatFormatting.GREEN)), + ComponentUtils.countableStatShow("Mutation Resistance", mutationResistance, bacteriaMutationResistanceCap) + .append(arrow) + .append(ComponentUtils.colored("[", ChatFormatting.GREEN)) + .append(ComponentUtils.statRange( + MathUtils.roundToPrecision(mutationResistance + 0.05f * (1 - mutationResistance / bacteriaMutationResistanceCap), 2), + MathUtils.roundToPrecision(mutationResistance + 0.1f, 2), + bacteriaMutationResistanceCap)) + .append(ComponentUtils.colored("]", ChatFormatting.GREEN)), + ComponentUtils.countableStatShow("Production Rate", productionRate, bacteriaProductionRateCap) + .append(arrow) + .append(ComponentUtils.colored("[", ChatFormatting.GREEN)) + .append(ComponentUtils.statRange( + MathUtils.roundToPrecision(productionRate + (-productionRate / (10 * (1 + mutationResistance))), 2), + MathUtils.roundToPrecision(productionRate + (productionRate / (10 * (1 + mutationResistance))), 2), + bacteriaProductionRateCap)) + .append(ComponentUtils.colored("]", ChatFormatting.GREEN)), + ComponentUtils.countableStatShow("Lifespan", lifespan, bacteriaLifespanCap) + .append(arrow) + .append(ComponentUtils.colored("[", ChatFormatting.GREEN)) + .append(ComponentUtils.statRange( + lifespan + (int) (-lifespan / (1 + mutationResistance)), + lifespan + (int) (lifespan / (1 + mutationResistance)), + bacteriaLifespanCap)) + .append(ComponentUtils.colored("]", ChatFormatting.GREEN)) + ); + } + @Override public BacteriaStatsSerializer getSerializer() { return Serializer.INSTANCE; @@ -68,6 +112,8 @@ public BacteriaStatsSerializer getSerializer() { @Override public BacteriaStats rollGrowthRate() { float newGR = growthRate + (RNGUtils.floatInRangeOf(growthRate) / (10 * (1 + mutationResistance))); + newGR = Math.max(newGR, 0); + newGR = Math.min(newGR, bacteriaGrowthRateCap); return new SimpleBacteriaStats(newGR, mutationResistance, productionRate, lifespan, color); @@ -75,7 +121,8 @@ public BacteriaStats rollGrowthRate() { @Override public BacteriaStats rollMutationResistance() { - float newMR = mutationResistance + RNGUtils.biasedInRange(0, 0.1f, mutationResistance) / 10 * (bacteriaMutationResistanceCap - mutationResistance); + float newMR = mutationResistance + RNGUtils.biasedInRange(0, 0.1f, mutationResistance / bacteriaMutationResistanceCap) / 10 * (bacteriaMutationResistanceCap - mutationResistance); + newMR = Math.max(newMR, 0); return new SimpleBacteriaStats(growthRate, newMR, productionRate, lifespan, color); } @@ -83,6 +130,8 @@ public BacteriaStats rollMutationResistance() { @Override public BacteriaStats rollProductionRate() { float newPR = productionRate + RNGUtils.floatInRangeOf(productionRate) / 10 * (1 + mutationResistance); + newPR = Math.max(newPR, 0); + newPR = Math.min(newPR, bacteriaProductionRateCap); return new SimpleBacteriaStats(growthRate, mutationResistance, newPR, lifespan, color); @@ -91,6 +140,8 @@ public BacteriaStats rollProductionRate() { @Override public BacteriaStats rollLifespan() { int newLS = lifespan + (int) (RNGUtils.uniformRandInt(-10, 10) / (1 + mutationResistance)); + newLS = Math.max(newLS, 0); + newLS = Math.min(newLS, bacteriaLifespanCap); return new SimpleBacteriaStats(growthRate, mutationResistance, productionRate, newLS, color); diff --git a/src/main/java/com/portingdeadmods/nautec/content/blockentities/MutatorBlockEntity.java b/src/main/java/com/portingdeadmods/nautec/content/blockentities/MutatorBlockEntity.java index 6c69e6c..d17f6f3 100644 --- a/src/main/java/com/portingdeadmods/nautec/content/blockentities/MutatorBlockEntity.java +++ b/src/main/java/com/portingdeadmods/nautec/content/blockentities/MutatorBlockEntity.java @@ -2,6 +2,7 @@ import com.portingdeadmods.nautec.NTConfig; import com.portingdeadmods.nautec.api.bacteria.Bacteria; +import com.portingdeadmods.nautec.api.bacteria.BacteriaInstance; import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity; import com.portingdeadmods.nautec.capabilities.IOActions; import com.portingdeadmods.nautec.capabilities.NTCapabilities; @@ -9,7 +10,6 @@ import com.portingdeadmods.nautec.content.menus.MutatorMenu; import com.portingdeadmods.nautec.data.NTDataComponents; import com.portingdeadmods.nautec.data.components.ComponentBacteriaStorage; -import com.portingdeadmods.nautec.registries.NTBacterias; import com.portingdeadmods.nautec.registries.NTBlockEntityTypes; import com.portingdeadmods.nautec.utils.BacteriaHelper; import it.unimi.dsi.fastutil.Pair; @@ -67,15 +67,14 @@ public void commonTick() { ItemStack result = extracted.copy(); -// Bacteria bacteria = BacteriaHelper.getBacteria(getLevel().getServer().registryAccess(), extracted.get(NTDataComponents.BACTERIA).bacteria()); -// bacteria.stats().rollStats(); -// -// result.set(NTDataComponents.BACTERIA, new ComponentBacteriaStorage( -// NTBacterias.EMPTY, -// 1 -// )); + BacteriaInstance instance = result.get(NTDataComponents.BACTERIA).bacteriaInstance(); + BacteriaHelper.rollBacteriaStats(instance); - getItemHandler().insertItem(1, result, false); + result.set(NTDataComponents.BACTERIA, new ComponentBacteriaStorage(instance)); + + forceInsertItem(1, result, false); + + progress = 0; } else { progress++; } diff --git a/src/main/java/com/portingdeadmods/nautec/content/items/PetriDishItem.java b/src/main/java/com/portingdeadmods/nautec/content/items/PetriDishItem.java index be57491..8c805ae 100644 --- a/src/main/java/com/portingdeadmods/nautec/content/items/PetriDishItem.java +++ b/src/main/java/com/portingdeadmods/nautec/content/items/PetriDishItem.java @@ -1,6 +1,7 @@ package com.portingdeadmods.nautec.content.items; import com.portingdeadmods.nautec.api.bacteria.Bacteria; +import com.portingdeadmods.nautec.api.bacteria.BacteriaInstance; import com.portingdeadmods.nautec.api.items.IBacteriaItem; import com.portingdeadmods.nautec.data.NTDataComponents; import com.portingdeadmods.nautec.registries.NTBacterias; @@ -24,24 +25,36 @@ public PetriDishItem(Properties properties) { @Override public void appendHoverText(ItemStack stack, TooltipContext context, List tooltipComponents, TooltipFlag tooltipFlag) { ResourceKey bacteriaType = stack.get(NTDataComponents.BACTERIA).bacteriaInstance().getBacteria(); - Bacteria bacteria = BacteriaHelper.getBacteria(context.registries(), bacteriaType); + BacteriaInstance bacteria = stack.get(NTDataComponents.BACTERIA).bacteriaInstance(); if (bacteria != null) { tooltipComponents.add(Component.literal("Name: ").append(Utils.registryTranslation(bacteriaType)).withStyle(ChatFormatting.WHITE)); if (bacteriaType != NTBacterias.EMPTY) { - MutableComponent statsCaption = Component.literal("Stats: "); + MutableComponent statsCaption = Component.literal("Stats: ").withStyle(ChatFormatting.WHITE); if (Boolean.TRUE.equals(stack.get(NTDataComponents.ANALYZED))) { if (!tooltipFlag.hasShiftDown()) { - statsCaption.append(""); + statsCaption + .append(Component.literal("<").withStyle(ChatFormatting.WHITE)) + .append(Component.literal("Shift").withStyle(ChatFormatting.YELLOW)) + .append(Component.literal(">").withStyle(ChatFormatting.WHITE)) + .append(Component.literal(" and ").withStyle(ChatFormatting.WHITE)) + .append(Component.literal("<").withStyle(ChatFormatting.WHITE)) + .append(Component.literal("Control").withStyle(ChatFormatting.YELLOW)) + .append(Component.literal(">").withStyle(ChatFormatting.WHITE)); } - tooltipComponents.add(statsCaption.withStyle(ChatFormatting.GRAY)); - if (tooltipFlag.hasShiftDown()) { - for (Component tooltipComponent : bacteria.initialStats().statsTooltip()) { - tooltipComponents.add(Component.literal(" ".repeat(2)).append(tooltipComponent).withStyle(ChatFormatting.GRAY)); + tooltipComponents.add(statsCaption); + if (tooltipFlag.hasShiftDown() && tooltipFlag.hasControlDown()) { + for (Component tooltipComponent : bacteria.getStats().statsTooltipWithMutatorValues()) { + tooltipComponents.add(Component.literal(" ".repeat(2)).append(tooltipComponent)); + } + } + if (tooltipFlag.hasShiftDown() && !tooltipFlag.hasControlDown()) { + for (Component tooltipComponent : bacteria.getStats().statsTooltip()) { + tooltipComponents.add(Component.literal(" ".repeat(2)).append(tooltipComponent)); } } } else { - statsCaption.append("???"); - tooltipComponents.add(statsCaption.withStyle(ChatFormatting.GRAY)); + statsCaption.append(Component.literal("???").withStyle(ChatFormatting.YELLOW)); + tooltipComponents.add(statsCaption); } } } diff --git a/src/main/java/com/portingdeadmods/nautec/utils/BacteriaHelper.java b/src/main/java/com/portingdeadmods/nautec/utils/BacteriaHelper.java index 2e28a87..02dacdb 100644 --- a/src/main/java/com/portingdeadmods/nautec/utils/BacteriaHelper.java +++ b/src/main/java/com/portingdeadmods/nautec/utils/BacteriaHelper.java @@ -2,6 +2,7 @@ import com.portingdeadmods.nautec.NTRegistries; import com.portingdeadmods.nautec.api.bacteria.Bacteria; +import com.portingdeadmods.nautec.api.bacteria.BacteriaInstance; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderLookup; import net.minecraft.resources.ResourceKey; @@ -14,4 +15,8 @@ public static Bacteria getBacteria(HolderLookup.Provider lookup, ResourceKey bacteriaHolderGetter.getOrThrow(bacteriaType).value()) .orElse(null); } + + public static void rollBacteriaStats(BacteriaInstance instance) { + instance.setStats(instance.getStats().rollStats()); + } } diff --git a/src/main/java/com/portingdeadmods/nautec/utils/ComponentUtils.java b/src/main/java/com/portingdeadmods/nautec/utils/ComponentUtils.java index 15f3449..bbaed9c 100644 --- a/src/main/java/com/portingdeadmods/nautec/utils/ComponentUtils.java +++ b/src/main/java/com/portingdeadmods/nautec/utils/ComponentUtils.java @@ -14,9 +14,9 @@ public static MutableComponent countableStatShow(String name, Number val, Number .append(Component.literal(": ").withStyle(ChatFormatting.WHITE)); if (val.doubleValue() < max.doubleValue()) { - mc1.append(colored(val.toString(), ChatFormatting.GREEN)); + mc1.append(colored(MathUtils.roundToPrecision(val.floatValue(), 2).toString(), ChatFormatting.GREEN)); } else { - mc1.append(colored(val.toString(), ChatFormatting.RED)); + mc1.append(colored(MathUtils.roundToPrecision(val.floatValue(), 2).toString(), ChatFormatting.RED)); } return mc1; @@ -27,4 +27,23 @@ public static MutableComponent stringStatShow(String name, String val) { .append(Component.literal(": ").withStyle(ChatFormatting.WHITE)) .append(colored(val, ChatFormatting.GREEN)); } + + public static MutableComponent statRange(Number val1, Number val2, Number max) { + if (val2.floatValue() >= max.floatValue()) { + return + colored(val1.toString(), ChatFormatting.WHITE) + .append(Component.literal(" - ").withStyle(ChatFormatting.YELLOW)) + .append(colored(max.toString(), ChatFormatting.RED)); + } else if (val1.floatValue() <= 0) { + return + colored("0", ChatFormatting.RED) + .append(Component.literal(" - ").withStyle(ChatFormatting.YELLOW)) + .append(colored(val2.toString(), ChatFormatting.WHITE)); + } else { + return + colored(val1.toString(), ChatFormatting.WHITE) + .append(Component.literal(" - ").withStyle(ChatFormatting.YELLOW)) + .append(colored(val2.toString(), ChatFormatting.WHITE)); + } + } } diff --git a/src/main/java/com/portingdeadmods/nautec/utils/MathUtils.java b/src/main/java/com/portingdeadmods/nautec/utils/MathUtils.java index b69ee50..b797dca 100644 --- a/src/main/java/com/portingdeadmods/nautec/utils/MathUtils.java +++ b/src/main/java/com/portingdeadmods/nautec/utils/MathUtils.java @@ -37,5 +37,9 @@ public static Vec3 rotateYawDegrees(Vec3 direction, double angleDegrees) { return new Vec3(newX, direction.y, newZ); } + + public static Float roundToPrecision(float value, int precision) { + return (float) Math.round(value * Math.pow(10, precision)) / (float) Math.pow(10, precision); + } } // Wow this class is full of maths, I guess the person who did it, is just good at maths :shrug: \ No newline at end of file From aba125447466f22b465f636d12eaa97fd98dd42a Mon Sep 17 00:00:00 2001 From: Reclipse <17797013+ReclipseTheOne@users.noreply.github.com> Date: Mon, 23 Dec 2024 04:19:22 +0200 Subject: [PATCH 4/4] You can dust suspicious gravel now but loottable still doesn't work --- .../processor_list/replace_with_suspicious_gravel.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/resources/data/nautec/worldgen/processor_list/replace_with_suspicious_gravel.json b/src/main/resources/data/nautec/worldgen/processor_list/replace_with_suspicious_gravel.json index 6614bb4..5e0186f 100644 --- a/src/main/resources/data/nautec/worldgen/processor_list/replace_with_suspicious_gravel.json +++ b/src/main/resources/data/nautec/worldgen/processor_list/replace_with_suspicious_gravel.json @@ -16,7 +16,11 @@ }, "output_state": { - "Name": "minecraft:suspicious_gravel" + "Name": "minecraft:suspicious_gravel", + "Properties": { + "dusted": 0, + "LootTable": "nautec:chests/ruins_rusty_crate" + } } } ]