Skip to content

Commit bafa712

Browse files
committed
lightningproof golems
1 parent 18d6549 commit bafa712

4 files changed

Lines changed: 31 additions & 11 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ loom.platform = forge
44
org.gradle.vfs.watch=true
55

66
# Mod properties
7-
mod_version = 1.11-pre12
7+
mod_version = 1.11-pre13
88
maven_group = cc.cassian.raspberry
99
archives_name = raspberry_core
1010

src/main/java/cc/cassian/raspberry/RaspberryMod.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public static void lightningTick(EntityStruckByLightningEvent event) {
111111
if (!ModCompat.hasCofhCore() && ModConfig.get().aftershock) {
112112
AftershockEvent.electrify(event);
113113
}
114+
if (ModCompat.hasCopperAgeBackport())
115+
CopperAgeBackportCompat.saveCopperGolem(event);
114116
}
115117

116118
@SubscribeEvent

src/main/java/cc/cassian/raspberry/compat/CopperAgeBackportCompat.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package cc.cassian.raspberry.compat;
22

33
import cc.cassian.raspberry.mixin.copperagebackport.CopperGolemEntityAccessor;
4+
import cc.cassian.raspberry.registry.RaspberryMobEffects;
45
import com.github.smallinger.copperagebackport.ModMemoryTypes;
56
import com.github.smallinger.copperagebackport.entity.CopperGolemEntity;
67
import com.github.smallinger.copperagebackport.registry.ModEntities;
78
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
89
import com.teamabnormals.caverns_and_chasms.core.other.tags.CCBlockTags;
910
import com.teamabnormals.caverns_and_chasms.core.registry.CCBlocks;
1011
import net.minecraft.core.BlockPos;
12+
import net.minecraft.world.effect.MobEffectInstance;
1113
import net.minecraft.world.entity.LivingEntity;
1214
import net.minecraft.world.level.Level;
1315
import net.minecraft.world.level.block.Blocks;
1416
import net.minecraft.world.level.block.CarvedPumpkinBlock;
1517
import net.minecraft.world.level.block.WeatheringCopper;
1618
import net.minecraft.world.level.block.state.BlockState;
19+
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
20+
import net.minecraftforge.eventbus.api.Event;
1721

1822
public class CopperAgeBackportCompat {
1923
public static void spawnCopperGolem(Level level, BlockPos pos, LocalRef<LivingEntity> golem, float yRot, BlockState abovestate) {
@@ -38,4 +42,14 @@ public static void spawnCopperGolem(Level level, BlockPos pos, LocalRef<LivingEn
3842
golem.set(copperGolem);
3943
copperGolem.moveTo((double)pos.getX() + (double)0.5F, (double)pos.getY() + 0.05, (double)pos.getZ() + (double)0.5F, yRot, 0.0F);
4044
}
45+
46+
public static void saveCopperGolem(EntityStruckByLightningEvent event) {
47+
if (event.getEntity() instanceof CopperGolemEntity) {
48+
event.setCanceled(true);
49+
}
50+
}
51+
52+
public static boolean isCopperGolem(LivingEntity entity) {
53+
return entity instanceof CopperGolemEntity;
54+
}
4155
}

src/main/java/cc/cassian/raspberry/events/AftershockEvent.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cc.cassian.raspberry.events;
22

33
import cc.cassian.raspberry.ModCompat;
4+
import cc.cassian.raspberry.compat.CopperAgeBackportCompat;
45
import cc.cassian.raspberry.registry.RaspberryMobEffects;
56
import cc.cassian.raspberry.registry.RaspberryTags;
67
import cofh.core.init.CoreMobEffects;
@@ -11,6 +12,7 @@
1112
import net.minecraft.world.entity.player.Player;
1213
import net.minecraft.world.item.ItemStack;
1314
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
15+
import org.jetbrains.annotations.Nullable;
1416

1517
public 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

Comments
 (0)