Skip to content

Commit 9c92b3b

Browse files
committed
make ScaredOfGargoyleGoal more reliable
1 parent d95ff12 commit 9c92b3b

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package galena.oreganized.mixin;
2+
3+
import galena.oreganized.world.ScaredOfGargoyleGoal;
4+
import net.minecraft.world.entity.Mob;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
9+
10+
@Mixin(Mob.class)
11+
public class MobMixin {
12+
13+
@Inject(
14+
method = "<init>",
15+
at = @At("RETURN")
16+
)
17+
private void addScaredOfGargoyleGoal(CallbackInfo ci) {
18+
var self = (Mob) (Object) this;
19+
if(self.level() == null || self.level().isClientSide()) return;
20+
ScaredOfGargoyleGoal.addGoal(self);
21+
}
22+
}

src/main/java/galena/oreganized/world/ScaredOfGargoyleGoal.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package galena.oreganized.world;
22

3-
import galena.oreganized.Oreganized;
43
import net.minecraft.nbt.NbtUtils;
5-
import net.minecraft.world.entity.Mob;
4+
import net.minecraft.world.entity.Entity;
65
import net.minecraft.world.entity.MobType;
76
import net.minecraft.world.entity.PathfinderMob;
87
import net.minecraft.world.entity.ai.goal.Goal;
98
import net.minecraft.world.entity.ai.navigation.PathNavigation;
109
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
1110
import net.minecraft.world.level.pathfinder.Path;
1211
import net.minecraft.world.phys.Vec3;
13-
import net.minecraftforge.event.entity.EntityEvent;
14-
import net.minecraftforge.eventbus.api.SubscribeEvent;
15-
import net.minecraftforge.fml.common.Mod;
1612

1713
import javax.annotation.Nullable;
14+
import java.util.EnumSet;
1815

19-
@Mod.EventBusSubscriber(modid = Oreganized.MOD_ID)
2016
public class ScaredOfGargoyleGoal extends Goal {
2117

2218
public static final String AVOID_TAG_KEY = "ScaredByGargoyle";
@@ -25,11 +21,9 @@ public class ScaredOfGargoyleGoal extends Goal {
2521

2622
private final PathfinderMob mob;
2723

28-
@SubscribeEvent
29-
public static void onMobSpawn(EntityEvent.EntityConstructing event) {
30-
if(!(event.getEntity() instanceof Mob entity)) return;
31-
if (entity.getMobType() == MobType.UNDEAD && entity instanceof PathfinderMob mob) {
32-
entity.goalSelector.addGoal(1, new ScaredOfGargoyleGoal(mob));
24+
public static void addGoal(Entity entity) {
25+
if (entity instanceof PathfinderMob mob && mob.getMobType() == MobType.UNDEAD) {
26+
mob.goalSelector.addGoal(1, new ScaredOfGargoyleGoal(mob));
3327
}
3428
}
3529

@@ -43,6 +37,7 @@ public static void onMobSpawn(EntityEvent.EntityConstructing event) {
4337
public ScaredOfGargoyleGoal(PathfinderMob mob) {
4438
this.mob = mob;
4539
this.navigation = mob.getNavigation();
40+
this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK));
4641
}
4742

4843
@Override

src/main/resources/oreganized.mixins.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
77
"AbstractArrowMixin", "BlockMixin", "CrossbowMixin", "DispenserBlockMixin", "EnchantmentHelperMixin", "EntityMixin",
8-
"FoodDataMixin", "IceBlockMixin", "LivingEntityMixin", "MobEffectInstanceMixin", "PillagerMixin", "PlayerMixin",
9-
"compat.AirCurrentMixin", "compat.BellowBlockTileMixin", "compat.LogStrippingFakeRecipesMixin"
8+
"FoodDataMixin", "IceBlockMixin", "LivingEntityMixin", "MobEffectInstanceMixin", "MobMixin", "PillagerMixin",
9+
"PlayerMixin", "compat.AirCurrentMixin", "compat.BellowBlockTileMixin", "compat.LogStrippingFakeRecipesMixin"
1010
],
1111
"client": [
1212
"client.GuiMixin", "client.HumanoidArmorLayerAccessor", "client.HumanoidArmorLayerMixin",

0 commit comments

Comments
 (0)