From 969efcc035aa1f16e6332c4f1ed8b72867d2413b Mon Sep 17 00:00:00 2001 From: Crim Date: Sun, 13 Oct 2024 15:10:57 +0800 Subject: [PATCH 1/5] Komodo Fix --- .../data/alexsmobs/tags/items/komodo_dragon_tameables.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/data/alexsmobs/tags/items/komodo_dragon_tameables.json b/src/main/resources/data/alexsmobs/tags/items/komodo_dragon_tameables.json index 5e8aecc98..d73d41ac6 100644 --- a/src/main/resources/data/alexsmobs/tags/items/komodo_dragon_tameables.json +++ b/src/main/resources/data/alexsmobs/tags/items/komodo_dragon_tameables.json @@ -1,4 +1,6 @@ { "replace": false, - "values": [] + "values": [ + "minecraft:rotten_flesh" + ] } \ No newline at end of file From 88ecd9982f2473902bc0b7937f628d23936fdcbf Mon Sep 17 00:00:00 2001 From: Crim Date: Mon, 11 Nov 2024 04:46:09 +0800 Subject: [PATCH 2/5] unique behaviors to vanilla mobs fix --- build.gradle | 7 ++- .../alexsmobs/entity/EntityCentipedeHead.java | 2 +- .../alexsmobs/entity/EntityGorilla.java | 3 +- .../alexsmobs/entity/EntityRattlesnake.java | 60 +++++++++++-------- .../alexsmobs/event/ServerEvents.java | 32 ---------- .../alexthe666/alexsmobs/mixins/CatMixin.java | 40 +++++++++++++ .../alexsmobs/mixins/CreeperMixin.java | 39 ++++++++++++ .../alexsmobs/mixins/DolphinMixin.java | 35 +++++++++++ .../alexthe666/alexsmobs/mixins/FoxMixin.java | 34 +++++++++++ .../alexsmobs/mixins/OcelotMixin.java | 34 +++++++++++ .../alexsmobs/mixins/PolarBearMixin.java | 37 ++++++++++++ .../alexsmobs/mixins/RabbitMixin.java | 36 +++++++++++ .../alexsmobs/mixins/SpiderMixin.java | 36 +++++++++++ .../alexsmobs/mixins/WolfMixin.java | 36 +++++++++++ src/main/resources/alexsmobs.mixins.json | 23 +++++++ 15 files changed, 392 insertions(+), 62 deletions(-) create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/CatMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/CreeperMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/DolphinMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/FoxMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/OcelotMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/PolarBearMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/RabbitMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/SpiderMixin.java create mode 100644 src/main/java/com/github/alexthe666/alexsmobs/mixins/WolfMixin.java create mode 100644 src/main/resources/alexsmobs.mixins.json diff --git a/build.gradle b/build.gradle index 3e7b71083..1a9d56e00 100644 --- a/build.gradle +++ b/build.gradle @@ -99,6 +99,7 @@ minecraft { } } } +apply plugin: 'org.spongepowered.mixin' // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } @@ -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.. diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java index 312a7e3ad..6c4db7cc1 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java @@ -170,7 +170,7 @@ public void pushEntities() { @Nullable public SpawnGroupData finalizeSpawn(ServerLevelAccessor worldIn, DifficultyInstance difficultyIn, MobSpawnType reason, @Nullable SpawnGroupData spawnDataIn, @Nullable CompoundTag dataTag) { - this.setSegmentCount(random.nextInt(4) + 5); + this.setSegmentCount(random.nextInt(4) + 100); return super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag); } diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java index 48f3c998c..113963118 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java @@ -147,8 +147,7 @@ protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(0, new FloatGoal(this)); this.goalSelector.addGoal(1, new SitWhenOrderedToGoal(this)); - this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.2D, true)); - this.goalSelector.addGoal(2, new GorillaAIFollowCaravan(this, 0.8D)); + this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.2D, false)); this.goalSelector.addGoal(3, new GorillaAIChargeLooker(this, 1.6D)); this.goalSelector.addGoal(4, new TameableAITempt(this, 1.1D, Ingredient.of(AMTagRegistry.GORILLA_TAMEABLES), false)); this.goalSelector.addGoal(4, new AnimalAIRideParent(this, 1.25D)); diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java index 681cce10f..a62724a23 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java @@ -34,6 +34,7 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nullable; +import java.util.Iterator; import java.util.List; import java.util.function.Predicate; @@ -62,7 +63,7 @@ protected EntityRattlesnake(EntityType type, Level worldIn) { protected void registerGoals() { this.goalSelector.addGoal(0, new FloatGoal(this)); - this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2D, true)); + this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2D, false)); this.goalSelector.addGoal(2, new WarnPredatorsGoal()); this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D)); @@ -242,45 +243,54 @@ public static boolean canRattlesnakeSpawn(EntityType animal, L class WarnPredatorsGoal extends Goal { int executionChance = 20; - Entity target = null; + LivingEntity target = null; + + private static final Predicate WARNABLE_PREDICATE = (mob) -> { + return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner || mob instanceof EntityRattlesnake; + }; + + public WarnPredatorsGoal() { + } - @Override public boolean canUse() { - if(EntityRattlesnake.this.getRandom().nextInt(executionChance) == 0){ - final double dist = 5D; - List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(dist, dist, dist), WARNABLE_PREDICATE); - double d0 = Double.MAX_VALUE; - Entity possibleTarget = null; - for(Entity entity : list) { - double d1 = EntityRattlesnake.this.distanceToSqr(entity); - if (!(d1 > d0)) { - d0 = d1; - possibleTarget = entity; - } + List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(5.0, 5.0, 5.0), WARNABLE_PREDICATE); + double d0 = Double.MAX_VALUE; + Entity possibleTarget = null; + Iterator var7 = list.iterator(); + + while(var7.hasNext()) { + + Entity entity = var7.next(); + double d1 = EntityRattlesnake.this.distanceToSqr(entity); + if (!(d1 > d0) && entity != EntityRattlesnake.this) { + d0 = d1; + possibleTarget = entity; } - target = possibleTarget; - return !list.isEmpty(); + } - return false; + + this.target = (LivingEntity) possibleTarget; + return !list.isEmpty(); + } - @Override - public boolean canContinueToUse(){ - return target != null && EntityRattlesnake.this.distanceTo(target) < 5D && EntityRattlesnake.this.getTarget() == null; + public boolean canContinueToUse() { + return this.target != null && (double)EntityRattlesnake.this.distanceTo(this.target) < 5.0 && EntityRattlesnake.this.getTarget() == null; } - @Override public void stop() { - target = null; + this.target = null; EntityRattlesnake.this.setRattling(false); } - @Override - public void tick(){ + public void tick() { + System.out.println("its working"); EntityRattlesnake.this.setRattling(true); EntityRattlesnake.this.setCurled(true); EntityRattlesnake.this.curlTime = 0; - EntityRattlesnake.this.getLookControl().setLookAt(target, 30, 30); + if (target != null){ + EntityRattlesnake.this.getLookControl().setLookAt(this.target, 30.0F, 30.0F); + } } } diff --git a/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java b/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java index a3043870a..ee39dcc96 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java @@ -506,38 +506,6 @@ public void onEntityFinalizeSpawn(MobSpawnEvent.FinalizeSpawn event) { } } } - 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 diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/CatMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/CatMixin.java new file mode 100644 index 000000000..06721a514 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/CatMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/CreeperMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/CreeperMixin.java new file mode 100644 index 000000000..27f8e585d --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/CreeperMixin.java @@ -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 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)); + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/DolphinMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/DolphinMixin.java new file mode 100644 index 000000000..2e3a904a8 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/DolphinMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/FoxMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/FoxMixin.java new file mode 100644 index 000000000..d38102655 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/FoxMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/OcelotMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/OcelotMixin.java new file mode 100644 index 000000000..622e68a0d --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/OcelotMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/PolarBearMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/PolarBearMixin.java new file mode 100644 index 000000000..abc6b9825 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/PolarBearMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/RabbitMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/RabbitMixin.java new file mode 100644 index 000000000..331b685e1 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/RabbitMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/SpiderMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/SpiderMixin.java new file mode 100644 index 000000000..c20c153f4 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/SpiderMixin.java @@ -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 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)); + } + } + +} diff --git a/src/main/java/com/github/alexthe666/alexsmobs/mixins/WolfMixin.java b/src/main/java/com/github/alexthe666/alexsmobs/mixins/WolfMixin.java new file mode 100644 index 000000000..34862ede0 --- /dev/null +++ b/src/main/java/com/github/alexthe666/alexsmobs/mixins/WolfMixin.java @@ -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.EntityMoose; +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.ai.goal.target.NonTameRandomTargetGoal; +import net.minecraft.world.entity.animal.Wolf; +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(Wolf.class) +public abstract class WolfMixin extends TamableAnimal { + + + protected WolfMixin(EntityType 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.wolvesAttackMoose) { + this.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(this, EntityMoose.class, false, null)); + } + } + +} diff --git a/src/main/resources/alexsmobs.mixins.json b/src/main/resources/alexsmobs.mixins.json new file mode 100644 index 000000000..bf618c437 --- /dev/null +++ b/src/main/resources/alexsmobs.mixins.json @@ -0,0 +1,23 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.alexthe666.alexsmobs.mixins", + "compatibilityLevel": "JAVA_8", + "refmap": "alexsmobs.refmap.json", + "mixins": [ + "CatMixin", + "CreeperMixin", + "DolphinMixin", + "FoxMixin", + "OcelotMixin", + "PolarBearMixin", + "RabbitMixin", + "SpiderMixin", + "WolfMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} From 4ab69ae5ea0c68e15b1f0ddfe0c51e99abf67612 Mon Sep 17 00:00:00 2001 From: Crim Date: Mon, 11 Nov 2024 04:50:06 +0800 Subject: [PATCH 3/5] unique behaviors to vanilla mobs fix --- .../java/com/github/alexthe666/alexsmobs/event/ServerEvents.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java b/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java index ee39dcc96..ad1662319 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/event/ServerEvents.java @@ -503,6 +503,7 @@ public void onEntityFinalizeSpawn(MobSpawnEvent.FinalizeSpawn event) { } elephant.addElephantLoot(null, RAND.nextInt()); } + } } } From a2e1a2f9f521ec8d05448019fbd3e07dfc9442c3 Mon Sep 17 00:00:00 2001 From: Crim Date: Mon, 11 Nov 2024 05:23:36 +0800 Subject: [PATCH 4/5] Revert --- .../alexsmobs/entity/EntityCentipedeHead.java | 2 +- .../alexsmobs/entity/EntityGorilla.java | 3 +- .../alexsmobs/entity/EntityRattlesnake.java | 233 +++++++++--------- 3 files changed, 125 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java index 6c4db7cc1..312a7e3ad 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityCentipedeHead.java @@ -170,7 +170,7 @@ public void pushEntities() { @Nullable public SpawnGroupData finalizeSpawn(ServerLevelAccessor worldIn, DifficultyInstance difficultyIn, MobSpawnType reason, @Nullable SpawnGroupData spawnDataIn, @Nullable CompoundTag dataTag) { - this.setSegmentCount(random.nextInt(4) + 100); + this.setSegmentCount(random.nextInt(4) + 5); return super.finalizeSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag); } diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java index 113963118..48f3c998c 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityGorilla.java @@ -147,7 +147,8 @@ protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(0, new FloatGoal(this)); this.goalSelector.addGoal(1, new SitWhenOrderedToGoal(this)); - this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.2D, false)); + this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.2D, true)); + this.goalSelector.addGoal(2, new GorillaAIFollowCaravan(this, 0.8D)); this.goalSelector.addGoal(3, new GorillaAIChargeLooker(this, 1.6D)); this.goalSelector.addGoal(4, new TameableAITempt(this, 1.1D, Ingredient.of(AMTagRegistry.GORILLA_TAMEABLES), false)); this.goalSelector.addGoal(4, new AnimalAIRideParent(this, 1.25D)); diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java index a62724a23..2f0074d19 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java @@ -1,3 +1,8 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + package com.github.alexthe666.alexsmobs.entity; import com.github.alexthe666.alexsmobs.config.AMConfig; @@ -7,6 +12,10 @@ import com.github.alexthe666.citadel.animation.Animation; import com.github.alexthe666.citadel.animation.AnimationHandler; import com.github.alexthe666.citadel.animation.IAnimatedEntity; +import java.util.Iterator; +import java.util.List; +import java.util.function.Predicate; +import javax.annotation.Nullable; import net.minecraft.core.BlockPos; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; @@ -17,10 +26,20 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.*; +import net.minecraft.world.entity.AgeableMob; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; -import net.minecraft.world.entity.ai.goal.*; +import net.minecraft.world.entity.ai.goal.BreedGoal; +import net.minecraft.world.entity.ai.goal.FloatGoal; +import net.minecraft.world.entity.ai.goal.FollowParentGoal; +import net.minecraft.world.entity.ai.goal.Goal; +import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; +import net.minecraft.world.entity.ai.goal.MeleeAttackGoal; +import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal; import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; import net.minecraft.world.entity.animal.Animal; @@ -33,55 +52,46 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3; -import javax.annotation.Nullable; -import java.util.Iterator; -import java.util.List; -import java.util.function.Predicate; - public class EntityRattlesnake extends Animal implements IAnimatedEntity { - public float prevCurlProgress; public float curlProgress; public int randomToungeTick = 0; public int maxCurlTime = 75; private int curlTime = 0; - private static final EntityDataAccessor RATTLING = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); - private static final EntityDataAccessor CURLED = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); - private static final Predicate WARNABLE_PREDICATE = (mob) -> { - return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; - }; - private static final Predicate TARGETABLE_PREDICATE = (mob) -> { - return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; - }; + private static final EntityDataAccessor RATTLING; + private static final EntityDataAccessor CURLED; + private static final Predicate WARNABLE_PREDICATE; + private static final Predicate TARGETABLE_PREDICATE; private int animationTick; private Animation currentAnimation; - public static final Animation ANIMATION_BITE = Animation.create(20); + public static final Animation ANIMATION_BITE; private int loopSoundTick = 0; + protected EntityRattlesnake(EntityType type, Level worldIn) { super(type, worldIn); } protected void registerGoals() { this.goalSelector.addGoal(0, new FloatGoal(this)); - this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2D, false)); + this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2, true)); this.goalSelector.addGoal(2, new WarnPredatorsGoal()); - this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); - this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D)); - this.goalSelector.addGoal(5, new AnimalAIWanderRanged(this, 60, 1.0D, 7, 7)); + this.goalSelector.addGoal(2, new BreedGoal(this, 1.0)); + this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1)); + this.goalSelector.addGoal(5, new AnimalAIWanderRanged(this, 60, 1.0, 7, 7)); this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 15.0F)); this.goalSelector.addGoal(7, new RandomLookAroundGoal(this)); - this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Rabbit.class, 15, true, true, null)); - this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, EntityJerboa.class, 15, true, true, null)); - this.targetSelector.addGoal(3, (new HurtByTargetGoal(this))); + this.targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, Rabbit.class, 15, true, true, (Predicate)null)); + this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, EntityJerboa.class, 15, true, true, (Predicate)null)); + this.targetSelector.addGoal(3, new HurtByTargetGoal(this, new Class[0])); this.targetSelector.addGoal(4, new ShortDistanceTarget()); } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { - return AMSoundRegistry.RATTLESNAKE_HURT.get(); + return (SoundEvent)AMSoundRegistry.RATTLESNAKE_HURT.get(); } protected SoundEvent getDeathSound() { - return AMSoundRegistry.RATTLESNAKE_HURT.get(); + return (SoundEvent)AMSoundRegistry.RATTLESNAKE_HURT.get(); } public boolean checkSpawnRules(LevelAccessor worldIn, MobSpawnType spawnReasonIn) { @@ -94,13 +104,9 @@ public boolean doHurtTarget(Entity entityIn) { } public boolean canBeAffected(MobEffectInstance potioneffectIn) { - if (potioneffectIn.getEffect() == MobEffects.POISON) { - return false; - } - return super.canBeAffected(potioneffectIn); + return potioneffectIn.getEffect() == MobEffects.POISON ? false : super.canBeAffected(potioneffectIn); } - @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(CURLED, false); @@ -108,7 +114,7 @@ protected void defineSynchedData() { } public boolean isCurled() { - return this.entityData.get(CURLED); + return (Boolean)this.entityData.get(CURLED); } public void setCurled(boolean curled) { @@ -116,74 +122,81 @@ public void setCurled(boolean curled) { } public boolean isRattling() { - return this.entityData.get(RATTLING); + return (Boolean)this.entityData.get(RATTLING); } public void setRattling(boolean rattling) { this.entityData.set(RATTLING, rattling); } - public void tick(){ + public void tick() { super.tick(); - prevCurlProgress = curlProgress; - + this.prevCurlProgress = this.curlProgress; if (this.isCurled()) { - if (curlProgress < 5F) - curlProgress += 0.5F; - } else { - if (curlProgress > 0F) - curlProgress--; + if (this.curlProgress < 5.0F) { + this.curlProgress += 0.5F; + } + } else if (this.curlProgress > 0.0F) { + --this.curlProgress; } - if (randomToungeTick == 0 && random.nextInt(15) == 0) { - randomToungeTick = 10 + random.nextInt(20); + if (this.randomToungeTick == 0 && this.random.nextInt(15) == 0) { + this.randomToungeTick = 10 + this.random.nextInt(20); } - if (randomToungeTick > 0) { - randomToungeTick--; + + if (this.randomToungeTick > 0) { + --this.randomToungeTick; } - if (isCurled() && !isRattling() && ++curlTime > maxCurlTime) { + + if (this.isCurled() && !this.isRattling() && ++this.curlTime > this.maxCurlTime) { this.setCurled(false); - curlTime = 0; - maxCurlTime = 75 + random.nextInt(50); + this.curlTime = 0; + this.maxCurlTime = 75 + this.random.nextInt(50); } LivingEntity target = this.getTarget(); if (!this.level().isClientSide) { - if (this.isCurled() && (target != null && target.isAlive())) { + if (this.isCurled() && target != null && target.isAlive()) { this.setCurled(false); } + if (this.isRattling() && target == null) { this.setCurled(true); - } - if (!this.isCurled() && this.getTarget() == null && random.nextInt(500) == 0) { - maxCurlTime = 300 + random.nextInt(250); + + if (!this.isCurled() && this.getTarget() == null && this.random.nextInt(500) == 0) { + this.maxCurlTime = 300 + this.random.nextInt(250); this.setCurled(true); } } + if (this.getAnimation() == ANIMATION_BITE) { if (this.getAnimationTick() == 4) { - this.playSound(AMSoundRegistry.RATTLESNAKE_ATTACK.get(), getSoundVolume(), getVoicePitch()); + this.playSound((SoundEvent)AMSoundRegistry.RATTLESNAKE_ATTACK.get(), this.getSoundVolume(), this.getVoicePitch()); } - if (this.getAnimationTick() == 8 && target != null && this.distanceTo(target) < 2D) { - final boolean meepMeep = target instanceof EntityRoadrunner; - final int f = isBaby() ? 2 : 1; - target.hurt(this.damageSources().mobAttack(this), meepMeep ? 1.0F : f * (float) getAttribute(Attributes.ATTACK_DAMAGE).getBaseValue()); + + if (this.getAnimationTick() == 8 && target != null && (double)this.distanceTo(target) < 2.0) { + boolean meepMeep = target instanceof EntityRoadrunner; + int f = this.isBaby() ? 2 : 1; + target.hurt(this.damageSources().mobAttack(this), meepMeep ? 1.0F : (float)f * (float)this.getAttribute(Attributes.ATTACK_DAMAGE).getBaseValue()); if (!meepMeep) { target.addEffect(new MobEffectInstance(MobEffects.POISON, 300, f * 2)); } } } - if(isRattling()){ - if(loopSoundTick == 0){ + + if (this.isRattling()) { + if (this.loopSoundTick == 0) { this.gameEvent(GameEvent.ENTITY_ROAR); - this.playSound(AMSoundRegistry.RATTLESNAKE_LOOP.get(), this.getSoundVolume() * 0.5F, this.getVoicePitch()); + this.playSound((SoundEvent)AMSoundRegistry.RATTLESNAKE_LOOP.get(), this.getSoundVolume() * 0.5F, this.getVoicePitch()); } - loopSoundTick++; - if(loopSoundTick > 50){ - loopSoundTick = 0; + + ++this.loopSoundTick; + if (this.loopSoundTick > 50) { + this.loopSoundTick = 0; } } + AnimationHandler.INSTANCE.updateAnimations(this); } @@ -192,13 +205,15 @@ public void travel(Vec3 vec3d) { if (this.getNavigation().getPath() != null) { this.getNavigation().stop(); } + vec3d = Vec3.ZERO; } + super.travel(vec3d); } public static AttributeSupplier.Builder bakeAttributes() { - return Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 8D).add(Attributes.ARMOR, 0.0D).add(Attributes.ATTACK_DAMAGE, 2.0D).add(Attributes.MOVEMENT_SPEED, 0.28F); + return Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 8.0).add(Attributes.ARMOR, 0.0).add(Attributes.ATTACK_DAMAGE, 2.0).add(Attributes.MOVEMENT_SPEED, 0.2800000011920929); } public boolean isFood(ItemStack stack) { @@ -206,32 +221,26 @@ public boolean isFood(ItemStack stack) { } @Nullable - @Override public AgeableMob getBreedOffspring(ServerLevel p_241840_1_, AgeableMob p_241840_2_) { - return AMEntityRegistry.RATTLESNAKE.get().create(p_241840_1_); + return (AgeableMob)((EntityType)AMEntityRegistry.RATTLESNAKE.get()).create(p_241840_1_); } - @Override public int getAnimationTick() { - return animationTick; + return this.animationTick; } - @Override public void setAnimationTick(int tick) { - animationTick = tick; + this.animationTick = tick; } - @Override public Animation getAnimation() { - return currentAnimation; + return this.currentAnimation; } - @Override public void setAnimation(Animation animation) { - currentAnimation = animation; + this.currentAnimation = animation; } - @Override public Animation[] getAnimations() { return new Animation[]{ANIMATION_BITE}; } @@ -239,39 +248,49 @@ public Animation[] getAnimations() { public static boolean canRattlesnakeSpawn(EntityType 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; -} + } + + static { + RATTLING = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); + CURLED = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); + WARNABLE_PREDICATE = (mob) -> { + return mob instanceof Player && !((Player)mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; + }; + TARGETABLE_PREDICATE = (mob) -> { + return mob instanceof Player && !((Player)mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; + }; + ANIMATION_BITE = Animation.create(20); + } class WarnPredatorsGoal extends Goal { int executionChance = 20; - LivingEntity target = null; + Entity target = null; - private static final Predicate WARNABLE_PREDICATE = (mob) -> { - return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner || mob instanceof EntityRattlesnake; - }; - - public WarnPredatorsGoal() { + WarnPredatorsGoal() { } public boolean canUse() { - List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(5.0, 5.0, 5.0), WARNABLE_PREDICATE); - double d0 = Double.MAX_VALUE; - Entity possibleTarget = null; - Iterator var7 = list.iterator(); - - while(var7.hasNext()) { - - Entity entity = var7.next(); - double d1 = EntityRattlesnake.this.distanceToSqr(entity); - if (!(d1 > d0) && entity != EntityRattlesnake.this) { - d0 = d1; - possibleTarget = entity; + if (EntityRattlesnake.this.getRandom().nextInt(this.executionChance) == 0) { + double dist = 5.0; + List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(5.0, 5.0, 5.0), EntityRattlesnake.WARNABLE_PREDICATE); + double d0 = Double.MAX_VALUE; + Entity possibleTarget = null; + Iterator var7 = list.iterator(); + + while(var7.hasNext()) { + Entity entity = (Entity)var7.next(); + double d1 = EntityRattlesnake.this.distanceToSqr(entity); + if (!(d1 > d0)) { + d0 = d1; + possibleTarget = entity; + } } + this.target = possibleTarget; + return !list.isEmpty(); + } else { + return false; } - - this.target = (LivingEntity) possibleTarget; - return !list.isEmpty(); - } public boolean canContinueToUse() { @@ -284,38 +303,30 @@ public void stop() { } public void tick() { - System.out.println("its working"); EntityRattlesnake.this.setRattling(true); EntityRattlesnake.this.setCurled(true); EntityRattlesnake.this.curlTime = 0; - if (target != null){ - EntityRattlesnake.this.getLookControl().setLookAt(this.target, 30.0F, 30.0F); - } + EntityRattlesnake.this.getLookControl().setLookAt(this.target, 30.0F, 30.0F); } } class ShortDistanceTarget extends NearestAttackableTargetGoal { public ShortDistanceTarget() { - super(EntityRattlesnake.this, Player.class, 3, true, true, TARGETABLE_PREDICATE); + super(EntityRattlesnake.this, Player.class, 3, true, true, EntityRattlesnake.TARGETABLE_PREDICATE); } public boolean canUse() { - if (EntityRattlesnake.this.isBaby()) { - return false; - } else { - return super.canUse(); - } + return EntityRattlesnake.this.isBaby() ? false : super.canUse(); } - public void start(){ + public void start() { super.start(); EntityRattlesnake.this.setCurled(false); EntityRattlesnake.this.setRattling(true); } protected double getFollowDistance() { - return 2D; + return 2.0; } } - } From 1103f7af9d5244555d6a74029118fd1d837c418f Mon Sep 17 00:00:00 2001 From: Crim Date: Mon, 11 Nov 2024 05:29:38 +0800 Subject: [PATCH 5/5] Revert 2 --- .../alexsmobs/entity/EntityRattlesnake.java | 219 ++++++++---------- 1 file changed, 99 insertions(+), 120 deletions(-) diff --git a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java index 2f0074d19..76c917781 100644 --- a/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java +++ b/src/main/java/com/github/alexthe666/alexsmobs/entity/EntityRattlesnake.java @@ -1,8 +1,3 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by FernFlower decompiler) -// - package com.github.alexthe666.alexsmobs.entity; import com.github.alexthe666.alexsmobs.config.AMConfig; @@ -12,10 +7,6 @@ import com.github.alexthe666.citadel.animation.Animation; import com.github.alexthe666.citadel.animation.AnimationHandler; import com.github.alexthe666.citadel.animation.IAnimatedEntity; -import java.util.Iterator; -import java.util.List; -import java.util.function.Predicate; -import javax.annotation.Nullable; import net.minecraft.core.BlockPos; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; @@ -26,20 +17,10 @@ import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.entity.AgeableMob; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; -import net.minecraft.world.entity.ai.goal.BreedGoal; -import net.minecraft.world.entity.ai.goal.FloatGoal; -import net.minecraft.world.entity.ai.goal.FollowParentGoal; -import net.minecraft.world.entity.ai.goal.Goal; -import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal; -import net.minecraft.world.entity.ai.goal.MeleeAttackGoal; -import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal; +import net.minecraft.world.entity.ai.goal.*; import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal; import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal; import net.minecraft.world.entity.animal.Animal; @@ -52,46 +33,54 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3; +import javax.annotation.Nullable; +import java.util.List; +import java.util.function.Predicate; + public class EntityRattlesnake extends Animal implements IAnimatedEntity { + public float prevCurlProgress; public float curlProgress; public int randomToungeTick = 0; public int maxCurlTime = 75; private int curlTime = 0; - private static final EntityDataAccessor RATTLING; - private static final EntityDataAccessor CURLED; - private static final Predicate WARNABLE_PREDICATE; - private static final Predicate TARGETABLE_PREDICATE; + private static final EntityDataAccessor RATTLING = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); + private static final EntityDataAccessor CURLED = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); + private static final Predicate WARNABLE_PREDICATE = (mob) -> { + return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; + }; + private static final Predicate TARGETABLE_PREDICATE = (mob) -> { + return mob instanceof Player && !((Player) mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; + }; private int animationTick; private Animation currentAnimation; - public static final Animation ANIMATION_BITE; + public static final Animation ANIMATION_BITE = Animation.create(20); private int loopSoundTick = 0; - protected EntityRattlesnake(EntityType type, Level worldIn) { super(type, worldIn); } protected void registerGoals() { this.goalSelector.addGoal(0, new FloatGoal(this)); - this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2, true)); + this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2D, true)); this.goalSelector.addGoal(2, new WarnPredatorsGoal()); - this.goalSelector.addGoal(2, new BreedGoal(this, 1.0)); - this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1)); - this.goalSelector.addGoal(5, new AnimalAIWanderRanged(this, 60, 1.0, 7, 7)); + this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D)); + this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D)); + this.goalSelector.addGoal(5, new AnimalAIWanderRanged(this, 60, 1.0D, 7, 7)); this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 15.0F)); this.goalSelector.addGoal(7, new RandomLookAroundGoal(this)); - this.targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, Rabbit.class, 15, true, true, (Predicate)null)); - this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, EntityJerboa.class, 15, true, true, (Predicate)null)); - this.targetSelector.addGoal(3, new HurtByTargetGoal(this, new Class[0])); + this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Rabbit.class, 15, true, true, null)); + this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, EntityJerboa.class, 15, true, true, null)); + this.targetSelector.addGoal(3, (new HurtByTargetGoal(this))); this.targetSelector.addGoal(4, new ShortDistanceTarget()); } protected SoundEvent getHurtSound(DamageSource damageSourceIn) { - return (SoundEvent)AMSoundRegistry.RATTLESNAKE_HURT.get(); + return AMSoundRegistry.RATTLESNAKE_HURT.get(); } protected SoundEvent getDeathSound() { - return (SoundEvent)AMSoundRegistry.RATTLESNAKE_HURT.get(); + return AMSoundRegistry.RATTLESNAKE_HURT.get(); } public boolean checkSpawnRules(LevelAccessor worldIn, MobSpawnType spawnReasonIn) { @@ -104,9 +93,13 @@ public boolean doHurtTarget(Entity entityIn) { } public boolean canBeAffected(MobEffectInstance potioneffectIn) { - return potioneffectIn.getEffect() == MobEffects.POISON ? false : super.canBeAffected(potioneffectIn); + if (potioneffectIn.getEffect() == MobEffects.POISON) { + return false; + } + return super.canBeAffected(potioneffectIn); } + @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(CURLED, false); @@ -114,7 +107,7 @@ protected void defineSynchedData() { } public boolean isCurled() { - return (Boolean)this.entityData.get(CURLED); + return this.entityData.get(CURLED); } public void setCurled(boolean curled) { @@ -122,81 +115,74 @@ public void setCurled(boolean curled) { } public boolean isRattling() { - return (Boolean)this.entityData.get(RATTLING); + return this.entityData.get(RATTLING); } public void setRattling(boolean rattling) { this.entityData.set(RATTLING, rattling); } - public void tick() { + public void tick(){ super.tick(); - this.prevCurlProgress = this.curlProgress; + prevCurlProgress = curlProgress; + if (this.isCurled()) { - if (this.curlProgress < 5.0F) { - this.curlProgress += 0.5F; - } - } else if (this.curlProgress > 0.0F) { - --this.curlProgress; + if (curlProgress < 5F) + curlProgress += 0.5F; + } else { + if (curlProgress > 0F) + curlProgress--; } - if (this.randomToungeTick == 0 && this.random.nextInt(15) == 0) { - this.randomToungeTick = 10 + this.random.nextInt(20); + if (randomToungeTick == 0 && random.nextInt(15) == 0) { + randomToungeTick = 10 + random.nextInt(20); } - - if (this.randomToungeTick > 0) { - --this.randomToungeTick; + if (randomToungeTick > 0) { + randomToungeTick--; } - - if (this.isCurled() && !this.isRattling() && ++this.curlTime > this.maxCurlTime) { + if (isCurled() && !isRattling() && ++curlTime > maxCurlTime) { this.setCurled(false); - this.curlTime = 0; - this.maxCurlTime = 75 + this.random.nextInt(50); + curlTime = 0; + maxCurlTime = 75 + random.nextInt(50); } LivingEntity target = this.getTarget(); if (!this.level().isClientSide) { - if (this.isCurled() && target != null && target.isAlive()) { + if (this.isCurled() && (target != null && target.isAlive())) { this.setCurled(false); } - if (this.isRattling() && target == null) { this.setCurled(true); - } - if (!this.isCurled() && this.getTarget() == null && this.random.nextInt(500) == 0) { - this.maxCurlTime = 300 + this.random.nextInt(250); + } + if (!this.isCurled() && this.getTarget() == null && random.nextInt(500) == 0) { + maxCurlTime = 300 + random.nextInt(250); this.setCurled(true); } } - if (this.getAnimation() == ANIMATION_BITE) { if (this.getAnimationTick() == 4) { - this.playSound((SoundEvent)AMSoundRegistry.RATTLESNAKE_ATTACK.get(), this.getSoundVolume(), this.getVoicePitch()); + this.playSound(AMSoundRegistry.RATTLESNAKE_ATTACK.get(), getSoundVolume(), getVoicePitch()); } - - if (this.getAnimationTick() == 8 && target != null && (double)this.distanceTo(target) < 2.0) { - boolean meepMeep = target instanceof EntityRoadrunner; - int f = this.isBaby() ? 2 : 1; - target.hurt(this.damageSources().mobAttack(this), meepMeep ? 1.0F : (float)f * (float)this.getAttribute(Attributes.ATTACK_DAMAGE).getBaseValue()); + if (this.getAnimationTick() == 8 && target != null && this.distanceTo(target) < 2D) { + final boolean meepMeep = target instanceof EntityRoadrunner; + final int f = isBaby() ? 2 : 1; + target.hurt(this.damageSources().mobAttack(this), meepMeep ? 1.0F : f * (float) getAttribute(Attributes.ATTACK_DAMAGE).getBaseValue()); if (!meepMeep) { target.addEffect(new MobEffectInstance(MobEffects.POISON, 300, f * 2)); } } } - - if (this.isRattling()) { - if (this.loopSoundTick == 0) { + if(isRattling()){ + if(loopSoundTick == 0){ this.gameEvent(GameEvent.ENTITY_ROAR); - this.playSound((SoundEvent)AMSoundRegistry.RATTLESNAKE_LOOP.get(), this.getSoundVolume() * 0.5F, this.getVoicePitch()); + this.playSound(AMSoundRegistry.RATTLESNAKE_LOOP.get(), this.getSoundVolume() * 0.5F, this.getVoicePitch()); } - - ++this.loopSoundTick; - if (this.loopSoundTick > 50) { - this.loopSoundTick = 0; + loopSoundTick++; + if(loopSoundTick > 50){ + loopSoundTick = 0; } } - AnimationHandler.INSTANCE.updateAnimations(this); } @@ -205,15 +191,13 @@ public void travel(Vec3 vec3d) { if (this.getNavigation().getPath() != null) { this.getNavigation().stop(); } - vec3d = Vec3.ZERO; } - super.travel(vec3d); } public static AttributeSupplier.Builder bakeAttributes() { - return Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 8.0).add(Attributes.ARMOR, 0.0).add(Attributes.ATTACK_DAMAGE, 2.0).add(Attributes.MOVEMENT_SPEED, 0.2800000011920929); + return Monster.createMonsterAttributes().add(Attributes.MAX_HEALTH, 8D).add(Attributes.ARMOR, 0.0D).add(Attributes.ATTACK_DAMAGE, 2.0D).add(Attributes.MOVEMENT_SPEED, 0.28F); } public boolean isFood(ItemStack stack) { @@ -221,26 +205,32 @@ public boolean isFood(ItemStack stack) { } @Nullable + @Override public AgeableMob getBreedOffspring(ServerLevel p_241840_1_, AgeableMob p_241840_2_) { - return (AgeableMob)((EntityType)AMEntityRegistry.RATTLESNAKE.get()).create(p_241840_1_); + return AMEntityRegistry.RATTLESNAKE.get().create(p_241840_1_); } + @Override public int getAnimationTick() { - return this.animationTick; + return animationTick; } + @Override public void setAnimationTick(int tick) { - this.animationTick = tick; + animationTick = tick; } + @Override public Animation getAnimation() { - return this.currentAnimation; + return currentAnimation; } + @Override public void setAnimation(Animation animation) { - this.currentAnimation = animation; + currentAnimation = animation; } + @Override public Animation[] getAnimations() { return new Animation[]{ANIMATION_BITE}; } @@ -250,83 +240,72 @@ public static boolean canRattlesnakeSpawn(EntityType animal, L return spawnBlock && worldIn.getRawBrightness(pos, 0) > 8; } - static { - RATTLING = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); - CURLED = SynchedEntityData.defineId(EntityRattlesnake.class, EntityDataSerializers.BOOLEAN); - WARNABLE_PREDICATE = (mob) -> { - return mob instanceof Player && !((Player)mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; - }; - TARGETABLE_PREDICATE = (mob) -> { - return mob instanceof Player && !((Player)mob).isCreative() && !mob.isSpectator() || mob instanceof EntityRoadrunner; - }; - ANIMATION_BITE = Animation.create(20); - } - class WarnPredatorsGoal extends Goal { int executionChance = 20; Entity target = null; - WarnPredatorsGoal() { - } - + @Override public boolean canUse() { - if (EntityRattlesnake.this.getRandom().nextInt(this.executionChance) == 0) { - double dist = 5.0; - List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(5.0, 5.0, 5.0), EntityRattlesnake.WARNABLE_PREDICATE); + if(EntityRattlesnake.this.getRandom().nextInt(executionChance) == 0){ + final double dist = 5D; + List list = EntityRattlesnake.this.level().getEntitiesOfClass(LivingEntity.class, EntityRattlesnake.this.getBoundingBox().inflate(dist, dist, dist), WARNABLE_PREDICATE); double d0 = Double.MAX_VALUE; Entity possibleTarget = null; - Iterator var7 = list.iterator(); - - while(var7.hasNext()) { - Entity entity = (Entity)var7.next(); + for(Entity entity : list) { double d1 = EntityRattlesnake.this.distanceToSqr(entity); if (!(d1 > d0)) { d0 = d1; possibleTarget = entity; } } - - this.target = possibleTarget; + target = possibleTarget; return !list.isEmpty(); - } else { - return false; } + return false; } - public boolean canContinueToUse() { - return this.target != null && (double)EntityRattlesnake.this.distanceTo(this.target) < 5.0 && EntityRattlesnake.this.getTarget() == null; + @Override + public boolean canContinueToUse(){ + return target != null && EntityRattlesnake.this.distanceTo(target) < 5D && EntityRattlesnake.this.getTarget() == null; } + @Override public void stop() { - this.target = null; + target = null; EntityRattlesnake.this.setRattling(false); } - public void tick() { + @Override + public void tick(){ EntityRattlesnake.this.setRattling(true); EntityRattlesnake.this.setCurled(true); EntityRattlesnake.this.curlTime = 0; - EntityRattlesnake.this.getLookControl().setLookAt(this.target, 30.0F, 30.0F); + EntityRattlesnake.this.getLookControl().setLookAt(target, 30, 30); } } class ShortDistanceTarget extends NearestAttackableTargetGoal { public ShortDistanceTarget() { - super(EntityRattlesnake.this, Player.class, 3, true, true, EntityRattlesnake.TARGETABLE_PREDICATE); + super(EntityRattlesnake.this, Player.class, 3, true, true, TARGETABLE_PREDICATE); } public boolean canUse() { - return EntityRattlesnake.this.isBaby() ? false : super.canUse(); + if (EntityRattlesnake.this.isBaby()) { + return false; + } else { + return super.canUse(); + } } - public void start() { + public void start(){ super.start(); EntityRattlesnake.this.setCurled(false); EntityRattlesnake.this.setRattling(true); } protected double getFollowDistance() { - return 2.0; + return 2D; } } -} + +} \ No newline at end of file