Make MekaSuit charge distribution unit able to charge curios slots when set to charge inventory
package mekanism.common.content.gear.mekasuit;
+import java.util.Optional;
import javax.annotation.ParametersAreNonnullByDefault;
import mekanism.api.Action;
import mekanism.api.energy.IEnergyContainer;
@@ -10,14 +11,17 @@ import mekanism.api.gear.config.IModuleConfigItem;
import mekanism.api.gear.config.ModuleBooleanData;
import mekanism.api.gear.config.ModuleConfigItemCreator;
import mekanism.api.math.FloatingLong;
+import mekanism.common.Mekanism;
import mekanism.common.MekanismLang;
import mekanism.common.config.MekanismConfig;
import mekanism.common.content.network.distribution.EnergySaveTarget;
+import mekanism.common.integration.MekanismHooks;
import mekanism.common.integration.energy.EnergyCompatUtils;
import mekanism.common.util.EmitUtils;
import mekanism.common.util.StorageUtils;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
+import net.minecraftforge.items.IItemHandler;
@ParametersAreNonnullByDefault
public class ModuleChargeDistributionUnit implements ICustomModule<ModuleChargeDistributionUnit> {
@@ -62,20 +66,33 @@ public class ModuleChargeDistributionUnit implements ICustomModule<ModuleChargeD
// first try to charge mainhand/offhand item
toCharge = charge(module, player, player.getMainHandItem(), toCharge);
toCharge = charge(module, player, player.getOffhandItem(), toCharge);
-
+ if (!toCharge.isZero()) {
for (ItemStack stack : player.inventory.items) {
- if (stack == player.getMainHandItem() || stack == player.getOffhandItem()) {
- continue;
+ if (stack != player.getMainHandItem() && stack != player.getOffhandItem()) {
+ toCharge = charge(module, player, stack, toCharge);
+ if (toCharge.isZero()) {
+ break;
+ }
+ }
}
+ if (!toCharge.isZero() && Mekanism.hooks.CuriosLoaded) {
+ Optional<? extends IItemHandler> curiosInventory = MekanismHooks.getCuriosInventory(player);
+ if (curiosInventory.isPresent()) {
+ IItemHandler handler = curiosInventory.get();
+ for (int slot = 0, slots = handler.getSlots(); slot < slots; slot++) {
+ toCharge = charge(module, player, handler.getStackInSlot(slot), toCharge);
if (toCharge.isZero()) {
break;
}
- toCharge = charge(module, player, stack, toCharge);
+ }
+ }
+ }
}
}
/** return rejects */
private FloatingLong charge(IModule<ModuleChargeDistributionUnit> module, PlayerEntity player, ItemStack stack, FloatingLong amount) {
+ if (!stack.isEmpty() && !amount.isZero()) {
IStrictEnergyHandler handler = EnergyCompatUtils.getStrictEnergyHandler(stack);
if (handler != null) {
FloatingLong remaining = handler.insertEnergy(amount, Action.SIMULATE);
@@ -84,6 +101,7 @@ public class ModuleChargeDistributionUnit implements ICustomModule<ModuleChargeD
return handler.insertEnergy(module.useEnergy(player, amount.subtract(remaining), false), Action.EXECUTE).add(remaining);
}
}
+ }
return amount;
}
}
\ No newline at end of file
