Make Electrolytic Breathing Unit fill any main hand item that can hold hydrogen
@@ -24,6 +24,7 @@ import mekanism.common.item.gear.ItemMekaSuitArmor;
import mekanism.common.lib.radiation.RadiationManager.RadiationScale;
import mekanism.common.lib.radiation.capability.IRadiationEntity;
import mekanism.common.registries.MekanismGases;
+import mekanism.common.registries.MekanismItems;
import mekanism.common.util.CapabilityUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.StorageUtils;
@@ -45,15 +46,21 @@ public abstract class ModuleMekaSuit extends Module {
@Override
public void tickServer(PlayerEntity player) {
- if (player.func_233571_b_(FluidTags.WATER) > 1.8) {
+ if (player.func_233571_b_(FluidTags.WATER) > 1.6) {
FloatingLong usage = MekanismConfig.general.FROM_H2.get().multiply(2);
long maxRate = Math.min(getMaxRate(), getContainerEnergy().divide(usage).intValue());
long hydrogenUsed = 0;
- GasStack hydrogenStack = new GasStack(MekanismGases.HYDROGEN.get(), maxRate * 2);
+ GasStack hydrogenStack = MekanismGases.HYDROGEN.getStack(maxRate * 2);
ItemStack chestStack = player.getItemStackFromSlot(EquipmentSlotType.CHEST);
- Optional<IGasHandler> capability = MekanismUtils.toOptional(chestStack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
- if (Modules.load(chestStack, Modules.JETPACK_UNIT) != null && capability.isPresent()) {
- hydrogenUsed = maxRate * 2 - capability.get().insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
+ Optional<IGasHandler> chestCapability = MekanismUtils.toOptional(chestStack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
+ if (checkChestPlate(chestStack) && chestCapability.isPresent()) {
+ hydrogenUsed = maxRate * 2 - chestCapability.get().insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
+ hydrogenStack.shrink(hydrogenUsed);
+ }
+ ItemStack handStack = player.getItemStackFromSlot(EquipmentSlotType.MAINHAND);
+ Optional<IGasHandler> handCapability = MekanismUtils.toOptional(handStack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY));
+ if (handCapability.isPresent()) {
+ hydrogenUsed = maxRate * 2 - handCapability.get().insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
}
long oxygenUsed = Math.min(maxRate, player.getMaxAir() - player.getAir());
long used = Math.max((int) Math.ceil(hydrogenUsed / 2D), oxygenUsed);
@@ -62,6 +69,21 @@ public abstract class ModuleMekaSuit extends Module {
}
}
+ /**
+ * Checks whether the given chestplate should be filled with hydrogen, if it can store hydrogen.
+ * Does not check whether the chestplate can store hydrogen.
+ *
+ * @param chestPlate the chestplate to check
+ * @return whether the given chestplate should be filled with hydrogen.
+ */
+ private boolean checkChestPlate(ItemStack chestPlate) {
+ if(chestPlate.getItem() == MekanismItems.MEKASUIT_BODYARMOR.get()) {
+ return Modules.load(chestPlate, Modules.JETPACK_UNIT) != null;
+ } else {
+ return true;
+ }
+ }
+
private int getMaxRate() {
return (int) Math.pow(2, getInstalledCount());
}
