Skip to content

Unique vanilla fix #2160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 1.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ minecraft {
}
}
}
apply plugin: 'org.spongepowered.mixin'

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }
Expand All @@ -114,8 +115,10 @@ dependencies {


mixin {
add sourceSets.main, "citadel.refmap.json"
config 'citadel.mixins.json'

add sourceSets.main, "alexsmobs.refmap.json"

config "alexsmobs.mixins.json"
}

// Example for how to get properties into the manifest for reading by the runtime..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public Animation[] getAnimations() {
public static boolean canRattlesnakeSpawn(EntityType<? extends Animal> animal, LevelAccessor worldIn, MobSpawnType reason, BlockPos pos, RandomSource random) {
boolean spawnBlock = worldIn.getBlockState(pos.below()).is(AMTagRegistry.RATTLESNAKE_SPAWNS);
return spawnBlock && worldIn.getRawBrightness(pos, 0) > 8;
}
}

class WarnPredatorsGoal extends Goal {
int executionChance = 20;
Expand Down Expand Up @@ -308,4 +308,4 @@ protected double getFollowDistance() {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -503,41 +503,10 @@ public void onEntityFinalizeSpawn(MobSpawnEvent.FinalizeSpawn event) {
}
elephant.addElephantLoot(null, RAND.nextInt());
}

}
}
}
try {
if (AMConfig.spidersAttackFlies && entity instanceof final Spider spider) {
spider.targetSelector.addGoal(4,
new NearestAttackableTargetGoal<>(spider, EntityFly.class, 1, true, false, null));
}
else if (AMConfig.wolvesAttackMoose && entity instanceof final Wolf wolf) {
wolf.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(wolf, EntityMoose.class, false, null));
}
else if (AMConfig.polarBearsAttackSeals && entity instanceof final PolarBear bear) {
bear.targetSelector.addGoal(6,
new NearestAttackableTargetGoal<>(bear, EntitySeal.class, 15, true, true, null));
}
else if (entity instanceof final Creeper creeper) {
creeper.targetSelector.addGoal(3, new AvoidEntityGoal<>(creeper, EntitySnowLeopard.class, 6.0F, 1.0D, 1.2D));
creeper.targetSelector.addGoal(3, new AvoidEntityGoal<>(creeper, EntityTiger.class, 6.0F, 1.0D, 1.2D));
}
else if (AMConfig.catsAndFoxesAttackJerboas
&& (entity instanceof Fox || entity instanceof Cat || entity instanceof Ocelot)) {
Mob mb = (Mob) entity;
mb.targetSelector.addGoal(6,
new NearestAttackableTargetGoal<>(mb, EntityJerboa.class, 45, true, true, null));
}
else if (AMConfig.bunfungusTransformation && entity instanceof final Rabbit rabbit) {
rabbit.goalSelector.addGoal(3, new TemptGoal(rabbit, 1.0D, Ingredient.of(AMItemRegistry.MUNGAL_SPORES.get()), false));
}
else if (AMConfig.dolphinsAttackFlyingFish && entity instanceof final Dolphin dolphin) {
dolphin.targetSelector.addGoal(2,
new NearestAttackableTargetGoal<>(dolphin, EntityFlyingFish.class, 70, true, true, null));
}
} catch (Exception e) {
AlexsMobs.LOGGER.warn("Tried to add unique behaviors to vanilla mobs and encountered an error");
}
}

@SubscribeEvent
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/com/github/alexthe666/alexsmobs/mixins/CatMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityJerboa;
import com.github.alexthe666.alexsmobs.entity.EntitySnowLeopard;
import com.github.alexthe666.alexsmobs.entity.EntityTiger;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.entity.animal.Ocelot;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.level.Level;
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(Cat.class)
public abstract class CatMixin extends TamableAnimal {


protected CatMixin(EntityType<? extends TamableAnimal> p_21803_, Level p_21804_) {
super(p_21803_, p_21804_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.catsAndFoxesAttackJerboas) {
this.targetSelector.addGoal(6, new NearestAttackableTargetGoal<>(this, EntityJerboa.class, 45, true, true, null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.entity.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


@Mixin(Creeper.class)
public abstract class CreeperMixin extends Monster {


protected CreeperMixin(EntityType<? extends Monster> p_33002_, Level p_33003_) {
super(p_33002_, p_33003_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
this.targetSelector.addGoal(3, new AvoidEntityGoal<>(this, EntitySnowLeopard.class, 6.0F, 1.0D, 1.2D));
this.targetSelector.addGoal(3, new AvoidEntityGoal<>(this, EntityTiger.class, 6.0F, 1.0D, 1.2D));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityFlyingFish;
import com.github.alexthe666.alexsmobs.entity.EntityJerboa;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.animal.Dolphin;
import net.minecraft.world.entity.animal.WaterAnimal;
import net.minecraft.world.level.Level;
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(Dolphin.class)
public abstract class DolphinMixin extends WaterAnimal {


protected DolphinMixin(EntityType<? extends WaterAnimal> p_30341_, Level p_30342_) {
super(p_30341_, p_30342_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.dolphinsAttackFlyingFish) {
this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, EntityFlyingFish.class, 70, true, true, null));
}
}

}
34 changes: 34 additions & 0 deletions src/main/java/com/github/alexthe666/alexsmobs/mixins/FoxMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityJerboa;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.level.Level;
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(Fox.class)
public abstract class FoxMixin extends Animal {


protected FoxMixin(EntityType<? extends TamableAnimal> p_21803_, Level p_21804_) {
super(p_21803_, p_21804_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.catsAndFoxesAttackJerboas) {
this.targetSelector.addGoal(6, new NearestAttackableTargetGoal<>(this, EntityJerboa.class, 45, true, true, null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityJerboa;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.entity.animal.Ocelot;
import net.minecraft.world.level.Level;
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(Ocelot.class)
public abstract class OcelotMixin extends Animal {


protected OcelotMixin(EntityType<? extends TamableAnimal> p_21803_, Level p_21804_) {
super(p_21803_, p_21804_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.catsAndFoxesAttackJerboas) {
this.targetSelector.addGoal(6, new NearestAttackableTargetGoal<>(this, EntityJerboa.class, 45, true, true, null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntitySeal;
import com.github.alexthe666.alexsmobs.entity.EntitySnowLeopard;
import com.github.alexthe666.alexsmobs.entity.EntityTiger;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.PolarBear;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.level.Level;
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(PolarBear.class)
public abstract class PolarBearMixin extends Animal {


protected PolarBearMixin(EntityType<? extends Animal> p_27557_, Level p_27558_) {
super(p_27557_, p_27558_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.polarBearsAttackSeals) {
this.targetSelector.addGoal(6, new NearestAttackableTargetGoal<>(this, EntitySeal.class, 15, true, true, null));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityJerboa;
import com.github.alexthe666.alexsmobs.item.AMItemRegistry;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.TamableAnimal;
import net.minecraft.world.entity.ai.goal.TemptGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.Rabbit;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
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(Rabbit.class)
public abstract class RabbitMixin extends Animal {


protected RabbitMixin(EntityType<? extends TamableAnimal> p_21803_, Level p_21804_) {
super(p_21803_, p_21804_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.bunfungusTransformation) {
this.goalSelector.addGoal(3, new TemptGoal(this, 1.0D, Ingredient.of(AMItemRegistry.MUNGAL_SPORES.get()), false));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.alexthe666.alexsmobs.mixins;


import com.github.alexthe666.alexsmobs.config.AMConfig;
import com.github.alexthe666.alexsmobs.entity.EntityFly;
import com.github.alexthe666.alexsmobs.entity.EntitySnowLeopard;
import com.github.alexthe666.alexsmobs.entity.EntityTiger;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.monster.Spider;
import net.minecraft.world.level.Level;
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(Spider.class)
public abstract class SpiderMixin extends Monster {


protected SpiderMixin(EntityType<? extends Monster> p_33002_, Level p_33003_) {
super(p_33002_, p_33003_);
}

@Inject(method = "registerGoals", at = @At("TAIL"), remap = false)
protected void registerGoals(CallbackInfo ci) {
if (AMConfig.spidersAttackFlies) {
this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, EntityFly.class, 1, true, false, null));
}
}

}
Loading