From 6c733e3479aab88691bb829e418a40c671faed67 Mon Sep 17 00:00:00 2001 From: tuc56 <57573828+tuc56@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:27:00 -0500 Subject: [PATCH 1/3] Check curios slots for radiation shielding(hopefully) --- .../common/lib/radiation/RadiationManager.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java index e8d661bcb84..b6b461a3e7b 100644 --- a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java +++ b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java @@ -35,6 +35,7 @@ import mekanism.common.Mekanism; import mekanism.common.capabilities.Capabilities; import mekanism.common.config.MekanismConfig; +import mekanism.common.integration.curios.CuriosIntegration; import mekanism.common.lib.MekanismSavedData; import mekanism.common.lib.collection.HashList; import mekanism.common.network.to_client.PacketRadiationData; @@ -66,6 +67,7 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -309,6 +311,21 @@ private double getRadiationResistance(LivingEntity entity) { resistance += shielding.get().getRadiationShielding(); } } + if (Mekanism.hooks.CuriosLoaded) { + Optional handlerOptional = CuriosIntegration.getCuriosInventory(entity); + if (handlerOptional.isPresent()) { + IItemHandler handler = handlerOptional.get(); + int slots = handler.getSlots(); + for (int i = 0; i < slots; i++) { + ItemStack item = handler.getStackInSlot(i); + Optional shielding = CapabilityUtils.getCapability(item, Capabilities.RADIATION_SHIELDING, null).resolve(); + if (shielding.isPresent()) { + resistance += shielding.get().getRadiationShielding(); + } + } + } + } + if (resistance > 1) resistance = 1; return resistance; } From 575ed2df91663258ba2fa63ac2e42db753d049b5 Mon Sep 17 00:00:00 2001 From: tuc56 <57573828+tuc56@users.noreply.github.com> Date: Sat, 24 Aug 2024 19:09:26 -0500 Subject: [PATCH 2/3] Add early returns --- .../java/mekanism/common/lib/radiation/RadiationManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java index b6b461a3e7b..906b992960e 100644 --- a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java +++ b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java @@ -311,6 +311,7 @@ private double getRadiationResistance(LivingEntity entity) { resistance += shielding.get().getRadiationShielding(); } } + if (resistance >= 1) return resistance; if (Mekanism.hooks.CuriosLoaded) { Optional handlerOptional = CuriosIntegration.getCuriosInventory(entity); if (handlerOptional.isPresent()) { @@ -321,11 +322,11 @@ private double getRadiationResistance(LivingEntity entity) { Optional shielding = CapabilityUtils.getCapability(item, Capabilities.RADIATION_SHIELDING, null).resolve(); if (shielding.isPresent()) { resistance += shielding.get().getRadiationShielding(); + if (resistance >= 1) return resistance; } } } } - if (resistance > 1) resistance = 1; return resistance; } From 0aa748e574f7ec4a3c375575fc778088ad6aeacd Mon Sep 17 00:00:00 2001 From: tuc56 <57573828+tuc56@users.noreply.github.com> Date: Sat, 24 Aug 2024 20:45:53 -0500 Subject: [PATCH 3/3] Add better early returns --- .../java/mekanism/common/lib/radiation/RadiationManager.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java index 906b992960e..7a00d6cbabe 100644 --- a/src/main/java/mekanism/common/lib/radiation/RadiationManager.java +++ b/src/main/java/mekanism/common/lib/radiation/RadiationManager.java @@ -311,8 +311,7 @@ private double getRadiationResistance(LivingEntity entity) { resistance += shielding.get().getRadiationShielding(); } } - if (resistance >= 1) return resistance; - if (Mekanism.hooks.CuriosLoaded) { + if (resistance < 1 && Mekanism.hooks.CuriosLoaded) { Optional handlerOptional = CuriosIntegration.getCuriosInventory(entity); if (handlerOptional.isPresent()) { IItemHandler handler = handlerOptional.get(); @@ -322,7 +321,7 @@ private double getRadiationResistance(LivingEntity entity) { Optional shielding = CapabilityUtils.getCapability(item, Capabilities.RADIATION_SHIELDING, null).resolve(); if (shielding.isPresent()) { resistance += shielding.get().getRadiationShielding(); - if (resistance >= 1) return resistance; + if (resistance >= 1) return 1; } } }