Skip to content

Commit

Permalink
allow reactors fuel output to be configured
Browse files Browse the repository at this point in the history
fix #99
  • Loading branch information
RogueLogix committed Nov 9, 2024
1 parent dc2d443 commit fae7653
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
12 changes: 12 additions & 0 deletions src/main/java/net/roguelogix/biggerreactors/Config.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package net.roguelogix.biggerreactors;

import net.minecraft.resources.ResourceLocation;
import net.roguelogix.phosphophyllite.config.ConfigFormat;
import net.roguelogix.phosphophyllite.config.ConfigType;
import net.roguelogix.phosphophyllite.config.ConfigValue;
import net.roguelogix.phosphophyllite.registry.RegisterConfig;
import net.roguelogix.phosphophyllite.util.NonnullDefault;
import org.jetbrains.annotations.Nullable;

@NonnullDefault
@SuppressWarnings("unused")
public class Config {

Expand Down Expand Up @@ -63,6 +67,14 @@ public static final class Reactor {
FuelMBPerIngot = 1000;
}

@Nullable
@ConfigValue
public final ResourceLocation FuelOutputItem;

{
FuelOutputItem = new ResourceLocation(BiggerReactors.modid, "uranium_ingot");
}

@ConfigValue(advanced = ConfigValue.BoolOption.True)
public final boolean useFullPassSimulation;
@ConfigValue(advanced = ConfigValue.BoolOption.True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.EmptyHandler;
import net.minecraftforge.registries.ForgeRegistries;
import net.roguelogix.biggerreactors.Config;
import net.roguelogix.biggerreactors.blocks.materials.MaterialBlock;
import net.roguelogix.biggerreactors.items.ingots.BlutoniumIngot;
Expand Down Expand Up @@ -53,12 +54,24 @@ public class ReactorAccessPortTile extends ReactorBaseTile implements IItemHandl
private static final TagKey<Item> uraniumIngotTag = TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation("forge:ingots/uranium"));
private static final TagKey<Item> uraniumBlockTag = TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation("forge:storage_blocks/uranium"));

private final Item fuelOutputItem;

public static final int FUEL_SLOT = 0;
public static final int WASTE_SLOT = 1;
public static final int FUEL_INSERT_SLOT = 2;

public ReactorAccessPortTile(BlockEntityType<?> tileEntityTypeIn, BlockPos pos, BlockState state) {
super(tileEntityTypeIn, pos, state);
if (Config.CONFIG.Reactor.FuelOutputItem != null) {
@Nullable
var potentialOutput = ForgeRegistries.ITEMS.getValue(Config.CONFIG.Reactor.FuelOutputItem);
if (potentialOutput == null || !potentialOutput.builtInRegistryHolder().is(uraniumIngotTag)) {
potentialOutput = UraniumIngot.INSTANCE;
}
fuelOutputItem = potentialOutput;
} else {
fuelOutputItem = UraniumIngot.INSTANCE;
}
}

private ReactorAccessPort.PortDirection direction = INLET;
Expand Down Expand Up @@ -131,15 +144,15 @@ public ItemStack getStackInSlot(int slot) {
return ItemStack.EMPTY;
}
var reactorSim = controller().simulation();
if(reactorSim == null){
if (reactorSim == null) {
return ItemStack.EMPTY;
}
if (slot == WASTE_SLOT) {
long availableIngots = reactorSim.fuelTank().waste() / Config.CONFIG.Reactor.FuelMBPerIngot;
return new ItemStack(CyaniteIngot.INSTANCE, (int) availableIngots);
} else if (slot == FUEL_SLOT) {
long availableIngots = reactorSim.fuelTank().fuel() / Config.CONFIG.Reactor.FuelMBPerIngot;
return new ItemStack(UraniumIngot.INSTANCE, (int) availableIngots);
return new ItemStack(fuelOutputItem, (int) availableIngots);
} else {
return ItemStack.EMPTY;
}
Expand Down Expand Up @@ -189,7 +202,7 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) {
long toExtracted = maxExtractable - (maxExtractable % Config.CONFIG.Reactor.FuelMBPerIngot);
long extracted = controller().extractFuel(toExtracted, simulate);

return new ItemStack(UraniumIngot.INSTANCE, (int) Math.min(amount, extracted / Config.CONFIG.Reactor.FuelMBPerIngot));
return new ItemStack(fuelOutputItem, (int) Math.min(amount, extracted / Config.CONFIG.Reactor.FuelMBPerIngot));
}

return ItemStack.EMPTY;
Expand All @@ -201,7 +214,7 @@ public int getSlotLimit(int slot) {
return 0;
}
var reactorSim = controller().simulation();
if(reactorSim == null){
if (reactorSim == null) {
return 0;
}
return (int) (reactorSim.fuelTank().capacity() / Config.CONFIG.Reactor.FuelMBPerIngot);
Expand All @@ -213,7 +226,7 @@ public boolean isItemValid(int slot, ItemStack stack) {
return stack.getItem().builtInRegistryHolder().is(uraniumIngotTag) || stack.getItem() == BlutoniumIngot.INSTANCE
|| stack.getItem().builtInRegistryHolder().is(uraniumBlockTag) || stack.getItem() == MaterialBlock.BLUTONIUM.asItem();
} else if (slot == FUEL_SLOT) {
return stack.getItem() == UraniumIngot.INSTANCE;
return stack.getItem() == fuelOutputItem;
} else {
return stack.getItem() == CyaniteIngot.INSTANCE;
}
Expand Down Expand Up @@ -251,7 +264,7 @@ public int pushFuel(int fuel, boolean simulated) {
if (fuel == 0) {
break;
}
ItemStack toInsertStack = new ItemStack(UraniumIngot.INSTANCE, fuel);
ItemStack toInsertStack = new ItemStack(fuelOutputItem, fuel);
ItemStack remainingStack = output.insertItem(i, toInsertStack, simulated);
fuelHandled += toInsertStack.getCount() - remainingStack.getCount();
fuel -= toInsertStack.getCount() - remainingStack.getCount();
Expand Down

0 comments on commit fae7653

Please sign in to comment.