Skip to content

Commit

Permalink
Mutator 1/2
Browse files Browse the repository at this point in the history
  • Loading branch information
ReclipseTheOne committed Dec 21, 2024
1 parent 95a7c95 commit f6358ee
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/portingdeadmods/nautec/NTConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ public final class NTConfig {
.comment("The maximum lifespan of a bacteria colony")
.defineInRange("bacteriaLifespanCap", 24000, 0, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue BACTERIA_ANALYZER_CRAFTING_SPEED = BUILDER
.comment("The amount of ticks it takes for the Bacterial Analyzer to analyze a Petri Dish")
.defineInRange("bacteriaAnalyzerCraftingSpeed", 60, 0, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue BACTERIA_ANALYZER_POWER_USAGE = BUILDER
.comment("The amount of power used by the Bacterial Analyzer each tick")
.defineInRange("bacteriaAnalyzerPowerUsage", 5, 0, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue MUTATOR_CRAFTING_SPEED = BUILDER
.comment("The amount of ticks it takes for the Bacterial Analyzer to analyze a Petri Dish")
.defineInRange("mutatorCraftingSpeed", 240, 0, Integer.MAX_VALUE);

private static final ModConfigSpec.IntValue MUTATOR_POWER_USAGE = BUILDER
.comment("The amount of power used by the Mutator each tick")
.defineInRange("mutatorPowerUsage", 10, 0, Integer.MAX_VALUE);



static final ModConfigSpec SPEC = BUILDER.build();

public static int kelpHeight;
Expand Down Expand Up @@ -130,6 +148,12 @@ public final class NTConfig {
public static float bacteriaColonySizeCap;
public static int bacteriaLifespanCap;

public static int bacteriaAnalyzerCraftingSpeed;
public static int bacteriaAnalyzerPowerUsage;

public static int mutatorCraftingSpeed;
public static int mutatorPowerUsage;

@SubscribeEvent
static void onLoad(final ModConfigEvent event) {
kelpHeight = KELP_HEIGHT.get();
Expand Down Expand Up @@ -163,6 +187,12 @@ static void onLoad(final ModConfigEvent event) {
bacteriaMutationResistanceCap = (float) BACTERIA_MUTATION_RESISTANCE_CAP.getAsDouble();
bacteriaColonySizeCap = (float) BACTERIA_COLONY_SIZE_CAP.getAsDouble();
bacteriaLifespanCap = BACTERIA_LIFESPAN_CAP.get();

bacteriaAnalyzerCraftingSpeed = BACTERIA_ANALYZER_CRAFTING_SPEED.get();
bacteriaAnalyzerPowerUsage = BACTERIA_ANALYZER_POWER_USAGE.get();

mutatorCraftingSpeed = MUTATOR_CRAFTING_SPEED.get();
mutatorPowerUsage = MUTATOR_POWER_USAGE.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@
import com.portingdeadmods.nautec.Nautec;
import com.portingdeadmods.nautec.api.client.screen.NTAbstractContainerScreen;
import com.portingdeadmods.nautec.api.menu.NTAbstractContainerMenu;
import com.portingdeadmods.nautec.content.blockentities.BacterialAnalyzerBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.MutatorBlockEntity;
import com.portingdeadmods.nautec.content.blockentities.multiblock.part.AugmentationStationExtensionBlockEntity;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import org.jetbrains.annotations.NotNull;

public class MutatorScreen extends NTAbstractContainerScreen<MutatorBlockEntity> {
public static final ResourceLocation TEXTURE = ResourceLocation.fromNamespaceAndPath(Nautec.MODID, "textures/gui/mutator.png");
public static final ResourceLocation PROGRESS_ARROW = Nautec.rl("container/mutator/progress_arrow");

public MutatorScreen(NTAbstractContainerMenu<MutatorBlockEntity> menu, Inventory playerInventory, Component title) {
super(menu, playerInventory, title);
this.titleLabelY = 4;
}

@Override
protected void renderBg(GuiGraphics guiGraphics, float delta, int mouseX, int mouseY) {
super.renderBg(guiGraphics, delta, mouseX, mouseY);
int i = this.leftPos;
int j = this.topPos;

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);
}

@Override
public @NotNull ResourceLocation getBackgroundTexture() {
return TEXTURE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.portingdeadmods.nautec.content.blockentities;

import com.portingdeadmods.nautec.NTConfig;
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.capabilities.NTCapabilities;
Expand All @@ -26,8 +27,8 @@
import java.util.Map;

public class BacterialAnalyzerBlockEntity extends LaserBlockEntity implements MenuProvider {
public static final int MAX_PROGRESS = 60;
public static final int POWER_USAGE = 5;
public static final int MAX_PROGRESS = NTConfig.bacteriaAnalyzerCraftingSpeed;
public static final int POWER_USAGE = NTConfig.bacteriaAnalyzerPowerUsage;

private boolean hasRecipe;
private int progress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.portingdeadmods.nautec.content.blockentities;

import com.portingdeadmods.nautec.NTConfig;
import com.portingdeadmods.nautec.api.bacteria.Bacteria;
import com.portingdeadmods.nautec.api.blockentities.LaserBlockEntity;
import com.portingdeadmods.nautec.capabilities.IOActions;
import com.portingdeadmods.nautec.capabilities.NTCapabilities;
import com.portingdeadmods.nautec.content.items.PetriDishItem;
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;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.core.BlockPos;
Expand All @@ -13,6 +21,7 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.capabilities.BlockCapability;
Expand All @@ -21,11 +30,58 @@
import java.util.Map;

public class MutatorBlockEntity extends LaserBlockEntity implements MenuProvider {
public static final int MAX_PROGRESS = NTConfig.mutatorCraftingSpeed;
public static final int POWER_USAGE = NTConfig.mutatorPowerUsage;

private boolean hasRecipe;
private int progress;

public MutatorBlockEntity(BlockPos blockPos, BlockState blockState) {
super(NTBlockEntityTypes.MUTATOR.get(), blockPos, blockState);
addItemHandler(1);
addItemHandler(3, 1, (slot, stack) -> (slot == 0 && stack.getItem() instanceof PetriDishItem) || slot == 1 || slot == 2);
}

@Override
protected void onItemsChanged(int slot) {
super.onItemsChanged(slot);

ItemStack stack = getItemHandler().getStackInSlot(0);
ItemStack resultStack = getItemHandler().getStackInSlot(1);
this.hasRecipe = stack.getCapability(NTCapabilities.BacteriaStorage.ITEM) != null
&& resultStack.isEmpty();
}

@Override
public void commonTick() {
super.commonTick();

if (hasRecipe) {
if (getPower() >= POWER_USAGE) {
if (progress >= MAX_PROGRESS) {
ItemStack extracted = getItemHandler().extractItem(0, 1, false);

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
));

getItemHandler().insertItem(1, result, false);
} else {
progress++;
}
}
} else {
progress = 0;
}
}

public int getProgress() {
return progress;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BioReactorPartBlockEntity extends BlockEntity implements Multiblock
private BlockPos controllerPos;

public BioReactorPartBlockEntity(BlockPos pos, BlockState blockState) {
super(NTBlockEntityTypes, pos, blockState);
super(NTBlockEntityTypes.BIO_REACTOR_PART.get(), pos, blockState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public BacterialAnalyzerMenu(int containerId, Inventory inv, FriendlyByteBuf ext
public BacterialAnalyzerMenu(int containerId, @NotNull Inventory inv, @NotNull BacterialAnalyzerBlockEntity blockEntity) {
super(NTMenuTypes.BACTERIAL_ANALYZER.get(), containerId, inv, blockEntity);

// Catalyst
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 0, 53, 38));
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 1, 107, 38));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ public MutatorMenu(int containerId, Inventory inv, FriendlyByteBuf extraData) {

public MutatorMenu(int containerId, @NotNull Inventory inv, @NotNull MutatorBlockEntity blockEntity) {
super(NTMenuTypes.MUTATOR.get(), containerId, inv, blockEntity);
// Input
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 0, 25, 25));

// Output
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 1, 133, 25));

// Catalyst
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 0, 80, 35));
addSlot(new SlotItemHandler(blockEntity.getItemHandler(), 2, 79, 54));

addPlayerInventory(inv, 84);
addPlayerHotbar(inv, 142);
}

@Override
protected int getMergeableSlotCount() {
return 1;
return 2;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f6358ee

Please sign in to comment.