Skip to content

Commit

Permalink
Guinea pigs will be targeted by, and run away from, foxes
Browse files Browse the repository at this point in the history
  • Loading branch information
seaneoo committed Nov 17, 2024
1 parent 4fb49c0 commit baede30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/main/java/dev/seano/sgp/mixin/FoxEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.seano.sgp.mixin;

import dev.seano.sgp.entity.ai.TargetGuineaPigGoal;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AnimalEntity;
import net.minecraft.entity.passive.FoxEntity;
import net.minecraft.world.World;
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(FoxEntity.class)
public abstract class FoxEntityMixin extends AnimalEntity {

protected FoxEntityMixin(EntityType<? extends AnimalEntity> entityType, World world) {
super(entityType, world);
}

@Inject(method = "initGoals", at = @At(value = "TAIL"))
private void initGoals(CallbackInfo ci) {
this.targetSelector.add(3, new TargetGuineaPigGoal(this));
}
}
7 changes: 3 additions & 4 deletions src/main/kotlin/dev/seano/sgp/entity/GuineaPigEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import net.minecraft.entity.data.DataTracker
import net.minecraft.entity.data.TrackedData
import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.entity.mob.CreeperEntity
import net.minecraft.entity.mob.MobEntity
import net.minecraft.entity.passive.*
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -42,8 +41,7 @@ class GuineaPigEntity(entityType: EntityType<out TameableEntity>?, world: World?


fun createAttributes(): DefaultAttributeContainer.Builder {
return MobEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, MAX_HEALTH)
return createMobAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, MAX_HEALTH)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.2)
}
}
Expand All @@ -64,6 +62,7 @@ class GuineaPigEntity(entityType: EntityType<out TameableEntity>?, world: World?
goalSelector.add(6, FleeEntityGoal(this, CreeperEntity::class.java, 6f, 1.0, 1.25))
goalSelector.add(6, FleeEntityGoal(this, OcelotEntity::class.java, 6f, 1.0, 1.25))
goalSelector.add(6, FleeEntityGoal(this, CatEntity::class.java, 6f, 1.0, 1.25))
goalSelector.add(6, FleeEntityGoal(this, FoxEntity::class.java, 6f, 1.0, 1.25))
goalSelector.add(7, FollowOwnerGoal(this, 1.1, 10.0f, 4.0f))
goalSelector.add(8, WanderAroundFarGoal(this, 1.0))
goalSelector.add(9, LookAtEntityGoal(this, PlayerEntity::class.java, 6.0f))
Expand Down Expand Up @@ -253,7 +252,7 @@ class GuineaPigEntity(entityType: EntityType<out TameableEntity>?, world: World?
} else if (!other.isTamed) {
false
} else {
if (other.isInSittingPose) false else this.isInLove && other.isInLove()
if (other.isInSittingPose) false else this.isInLove && other.isInLove
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/sgp.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_21",
"mixins": [
"CatEntityMixin",
"FoxEntityMixin",
"OcelotEntityMixin"
],
"injectors": {
Expand Down

0 comments on commit baede30

Please sign in to comment.