Skip to content

Commit

Permalink
make ScaredOfGargoyleGoal more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Oct 31, 2024
1 parent d95ff12 commit 9c92b3b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
22 changes: 22 additions & 0 deletions src/main/java/galena/oreganized/mixin/MobMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package galena.oreganized.mixin;

import galena.oreganized.world.ScaredOfGargoyleGoal;
import net.minecraft.world.entity.Mob;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Mob.class)
public class MobMixin {

@Inject(
method = "<init>",
at = @At("RETURN")
)
private void addScaredOfGargoyleGoal(CallbackInfo ci) {
var self = (Mob) (Object) this;
if(self.level() == null || self.level().isClientSide()) return;
ScaredOfGargoyleGoal.addGoal(self);
}
}
17 changes: 6 additions & 11 deletions src/main/java/galena/oreganized/world/ScaredOfGargoyleGoal.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package galena.oreganized.world;

import galena.oreganized.Oreganized;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nullable;
import java.util.EnumSet;

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

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

private final PathfinderMob mob;

@SubscribeEvent
public static void onMobSpawn(EntityEvent.EntityConstructing event) {
if(!(event.getEntity() instanceof Mob entity)) return;
if (entity.getMobType() == MobType.UNDEAD && entity instanceof PathfinderMob mob) {
entity.goalSelector.addGoal(1, new ScaredOfGargoyleGoal(mob));
public static void addGoal(Entity entity) {
if (entity instanceof PathfinderMob mob && mob.getMobType() == MobType.UNDEAD) {
mob.goalSelector.addGoal(1, new ScaredOfGargoyleGoal(mob));
}
}

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

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/oreganized.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AbstractArrowMixin", "BlockMixin", "CrossbowMixin", "DispenserBlockMixin", "EnchantmentHelperMixin", "EntityMixin",
"FoodDataMixin", "IceBlockMixin", "LivingEntityMixin", "MobEffectInstanceMixin", "PillagerMixin", "PlayerMixin",
"compat.AirCurrentMixin", "compat.BellowBlockTileMixin", "compat.LogStrippingFakeRecipesMixin"
"FoodDataMixin", "IceBlockMixin", "LivingEntityMixin", "MobEffectInstanceMixin", "MobMixin", "PillagerMixin",
"PlayerMixin", "compat.AirCurrentMixin", "compat.BellowBlockTileMixin", "compat.LogStrippingFakeRecipesMixin"
],
"client": [
"client.GuiMixin", "client.HumanoidArmorLayerAccessor", "client.HumanoidArmorLayerMixin",
Expand Down

0 comments on commit 9c92b3b

Please sign in to comment.