Skip to content

Commit

Permalink
Support oxygen fill for Electrolytic Breathing Unit
Browse files Browse the repository at this point in the history
- Add configs for "Fill Hydrogen" and "Fill Oxygen"
  • Loading branch information
bukowski912 committed Jan 28, 2025
1 parent 8745710 commit d4e522b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,8 @@ private void addMisc() {
addModuleConfig(ModuleGravitationalModulatingUnit.SPEED_BOOST, "Speed Boost");
add(MekanismLang.MODULE_VISION_ENHANCEMENT, "Vision Enhancement");
addModuleConfig(ModuleElectrolyticBreathingUnit.FILL_HELD, "Fill Held");
addModuleConfig(ModuleElectrolyticBreathingUnit.FILL_HYDROGEN, "Fill Hydrogen Tanks");
addModuleConfig(ModuleElectrolyticBreathingUnit.FILL_OXYGEN, "Fill Oxygen Tanks");
addModuleConfig(ModuleInhalationPurificationUnit.BENEFICIAL_EFFECTS, "Remove Beneficial");
addModuleConfig(ModuleInhalationPurificationUnit.NEUTRAL_EFFECTS, "Remove Neutral");
addModuleConfig(ModuleInhalationPurificationUnit.HARMFUL_EFFECTS, "Remove Harmful");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,62 @@
import net.neoforged.neoforge.fluids.FluidType;

@ParametersAreNotNullByDefault
public record ModuleElectrolyticBreathingUnit(boolean fillHeld) implements ICustomModule<ModuleElectrolyticBreathingUnit> {
public record ModuleElectrolyticBreathingUnit(boolean fillHeld, boolean fillHydrogen, boolean fillOxygen) implements ICustomModule<ModuleElectrolyticBreathingUnit> {

public static final ResourceLocation FILL_HELD = Mekanism.rl("breathing.held");
public static final ResourceLocation FILL_HYDROGEN = Mekanism.rl("breathing.hydrogen");
public static final ResourceLocation FILL_OXYGEN = Mekanism.rl("breathing.oxygen");

public ModuleElectrolyticBreathingUnit(IModule<ModuleElectrolyticBreathingUnit> module) {
this(module.getBooleanConfigOrFalse(FILL_HELD));
this(module.getBooleanConfigOrFalse(FILL_HELD), module.getBooleanConfigOrFalse(FILL_HYDROGEN), module.getBooleanConfigOrFalse(FILL_OXYGEN));
}

private long produceHydrogen(Player player, int maxRate) {
if (!fillHydrogen) {
return 0;
}
long hydrogenUsed = 0;
ChemicalStack hydrogenStack = MekanismChemicals.HYDROGEN.getStack(maxRate * 2L);
ItemStack chestStack = player.getItemBySlot(EquipmentSlot.CHEST);
if (checkChestPlate(chestStack)) {
IChemicalHandler chestCapability = Capabilities.CHEMICAL.getCapability(chestStack);
if (chestCapability != null) {
hydrogenUsed = maxRate * 2L - chestCapability.insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
hydrogenStack.shrink(hydrogenUsed);
}
}
if (fillHeld) {
ItemStack handStack = player.getItemBySlot(EquipmentSlot.MAINHAND);
IChemicalHandler handCapability = Capabilities.CHEMICAL.getCapability(handStack);
if (handCapability != null) {
hydrogenUsed = maxRate * 2L - handCapability.insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
}
}
return hydrogenUsed;
}

private long produceOxygen(Player player, int maxRate) {
if (!fillOxygen) {
int oxygenUsed = Math.min(maxRate, player.getMaxAirSupply() - player.getAirSupply());
player.setAirSupply(player.getAirSupply() + oxygenUsed);
return oxygenUsed;
}
long oxygenUsed = 0;
ChemicalStack oxygenStack = MekanismChemicals.OXYGEN.getStack(maxRate);
ItemStack chestStack = player.getItemBySlot(EquipmentSlot.CHEST);
IChemicalHandler chestCapability = Capabilities.CHEMICAL.getCapability(chestStack);
if (chestCapability != null) {
oxygenUsed = maxRate - chestCapability.insertChemical(oxygenStack, Action.EXECUTE).getAmount();
oxygenStack.shrink(oxygenUsed);
}
if (fillHeld) {
ItemStack handStack = player.getItemBySlot(EquipmentSlot.MAINHAND);
IChemicalHandler handCapability = Capabilities.CHEMICAL.getCapability(handStack);
if (handCapability != null) {
oxygenUsed = maxRate - handCapability.insertChemical(oxygenStack, Action.EXECUTE).getAmount();
}
}
return oxygenUsed;
}

@Override
Expand Down Expand Up @@ -61,27 +111,10 @@ public void tickServer(IModule<ModuleElectrolyticBreathingUnit> module, IModuleC
if (productionRate > 0) {
long usage = 2 * MekanismConfig.general.FROM_H2.get();
int maxRate = MathUtils.clampToInt(Math.min(productionRate, module.getContainerEnergy(stack) / usage));
long hydrogenUsed = 0;
ChemicalStack hydrogenStack = MekanismChemicals.HYDROGEN.getStack(maxRate * 2L);
ItemStack chestStack = player.getItemBySlot(EquipmentSlot.CHEST);
if (checkChestPlate(chestStack)) {
IChemicalHandler chestCapability = Capabilities.CHEMICAL.getCapability(chestStack);
if (chestCapability != null) {
hydrogenUsed = maxRate * 2L - chestCapability.insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
hydrogenStack.shrink(hydrogenUsed);
}
}
if (fillHeld) {
ItemStack handStack = player.getItemBySlot(EquipmentSlot.MAINHAND);
IChemicalHandler handCapability = Capabilities.CHEMICAL.getCapability(handStack);
if (handCapability != null) {
hydrogenUsed = maxRate * 2L - handCapability.insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
}
}
int oxygenUsed = Math.min(maxRate, player.getMaxAirSupply() - player.getAirSupply());
long hydrogenUsed = produceHydrogen(player, maxRate);
long oxygenUsed = produceOxygen(player, maxRate);
long used = Math.max(Mth.ceil(hydrogenUsed / 2D), oxygenUsed);
module.useEnergy(player, stack, MathUtils.multiplyClamped(usage, used));
player.setAirSupply(player.getAirSupply() + oxygenUsed);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mekanism/common/registries/MekanismModules.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ private MekanismModules() {
public static final ModuleRegistryObject<ModuleElectrolyticBreathingUnit> ELECTROLYTIC_BREATHING_UNIT = MODULES.register("electrolytic_breathing_unit",
ModuleElectrolyticBreathingUnit::new, () -> MekanismItems.MODULE_ELECTROLYTIC_BREATHING.asItem(), builder -> builder.maxStackSize(4)
.addConfig(ModuleBooleanConfig.create(ModuleElectrolyticBreathingUnit.FILL_HELD, true))
.addConfig(ModuleBooleanConfig.create(ModuleElectrolyticBreathingUnit.FILL_HYDROGEN, true))
.addConfig(ModuleBooleanConfig.create(ModuleElectrolyticBreathingUnit.FILL_OXYGEN, false))
);
public static final ModuleRegistryObject<ModuleInhalationPurificationUnit> INHALATION_PURIFICATION_UNIT = MODULES.register("inhalation_purification_unit",
ModuleInhalationPurificationUnit::new, () -> MekanismItems.MODULE_INHALATION_PURIFICATION.asItem(), builder -> builder
Expand Down

0 comments on commit d4e522b

Please sign in to comment.