11package cc .cassian .raspberry .events ;
22
33import cc .cassian .raspberry .ModCompat ;
4+ import cc .cassian .raspberry .compat .CopperAgeBackportCompat ;
45import cc .cassian .raspberry .registry .RaspberryMobEffects ;
56import cc .cassian .raspberry .registry .RaspberryTags ;
67import cofh .core .init .CoreMobEffects ;
1112import net .minecraft .world .entity .player .Player ;
1213import net .minecraft .world .item .ItemStack ;
1314import net .minecraftforge .event .entity .EntityStruckByLightningEvent ;
15+ import org .jetbrains .annotations .Nullable ;
1416
1517public class AftershockEvent {
1618
@@ -20,14 +22,8 @@ public class AftershockEvent {
2022 */
2123 public static void electrify (EntityStruckByLightningEvent event ) {
2224 Entity entity = event .getEntity ();
23- int copperCount = 0 ;
2425 if (entity instanceof LivingEntity player ) {
25- for (ItemStack armorSlot : entity .getArmorSlots ()) {
26- if (armorSlot .is (RaspberryTags .COPPER_ARMOR )) {
27- copperCount ++;
28- }
29- }
30- copperCount --;
26+ int copperCount = getCopperCount (player );
3127 if (copperCount >= 0 ) {
3228 if (!ModCompat .hasCofhCore ())
3329 player .addEffect (new MobEffectInstance (MobEffects .DAMAGE_RESISTANCE , 20 , copperCount , false , false , false ));
@@ -42,18 +38,26 @@ public static void electrify(EntityStruckByLightningEvent event) {
4238 * Implemented via mixin.
4339 */
4440 public static void resist (LivingEntity entity ) {
41+ int copperCount = getCopperCount (entity );
42+ if (copperCount >= 0 ) {
43+ entity .addEffect (new MobEffectInstance (CoreMobEffects .LIGHTNING_RESISTANCE .get (), 202 , 0 , false , false , true ));
44+ }
45+ }
46+
47+ private static int getCopperCount (LivingEntity entity ) {
4548 int copperCount = 0 ;
4649 if (entity instanceof Player player && player .isLocalPlayer ()) {
47- return ;
50+ return 0 ;
4851 }
4952 for (ItemStack armorSlot : entity .getArmorSlots ()) {
5053 if (armorSlot .is (RaspberryTags .COPPER_ARMOR )) {
5154 copperCount ++;
5255 }
5356 }
5457 copperCount --;
55- if (copperCount >= 0 ) {
56- entity . addEffect ( new MobEffectInstance ( CoreMobEffects . LIGHTNING_RESISTANCE . get (), 202 , 0 , false , false , true )) ;
58+ if (ModCompat . hasCopperAgeBackport () && CopperAgeBackportCompat . isCopperGolem ( entity ) ) {
59+ copperCount = 2 ;
5760 }
61+ return copperCount ;
5862 }
5963}
0 commit comments