aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2023-11-06 14:47:46 -0600
committercitrons <citrons@mondecitronne.com>2023-11-06 14:47:46 -0600
commit8408acffa12c65ef5690c153ffd0e0be962d1045 (patch)
tree3a8f7312e640c622bc7b619989b39d92663ceef5
parent26cdb5e8c1d58d46f3819ce44fb1fc17826296e2 (diff)
homunculi may be "variant"
-rw-r--r--src/main/java/com/mondecitronne/homunculus/EntityAIMasochism.java63
-rw-r--r--src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java14
2 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/com/mondecitronne/homunculus/EntityAIMasochism.java b/src/main/java/com/mondecitronne/homunculus/EntityAIMasochism.java
new file mode 100644
index 0000000..e0643fd
--- /dev/null
+++ b/src/main/java/com/mondecitronne/homunculus/EntityAIMasochism.java
@@ -0,0 +1,63 @@
+package com.mondecitronne.homunculus;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.ai.EntityAIBase;
+
+public class EntityAIMasochism extends EntityAIBase {
+ protected EntityHomunculus homunculus;
+ protected Entity dominant;
+
+ private final float targetDistance;
+ private final double speed;
+ private int interestTimer;
+
+ public EntityAIMasochism(EntityHomunculus entityIn, double moveSpeed, float maxTargetDistance) {
+ homunculus = entityIn;
+ speed = moveSpeed;
+ targetDistance = maxTargetDistance;
+ interestTimer = 0;
+ }
+
+ protected boolean interestElapsed() {
+ return homunculus.ticksExisted - interestTimer > 1200;
+ }
+
+ protected void resetInterest() {
+ interestTimer = homunculus.ticksExisted;
+ }
+
+ @Override
+ public boolean shouldExecute() {
+ if (!homunculus.isMasochist()) {
+ return false;
+ }
+ if (dominant != null && !interestElapsed()) {
+ return true;
+ }
+ dominant = homunculus.getRevengeTarget();
+ resetInterest();
+ return dominant != null;
+ }
+
+ @Override
+ public boolean shouldContinueExecuting() {
+ return !homunculus.getNavigator().noPath() &&
+ dominant.isEntityAlive() &&
+ !interestElapsed() &&
+ dominant.getDistanceSq(homunculus) < (double) (targetDistance * targetDistance);
+ }
+
+ @Override
+ public void startExecuting() {
+ if (dominant.getDistanceSq(homunculus) > 8.0) {
+ homunculus.getNavigator().tryMoveToEntityLiving(dominant, speed);
+ }
+ updateTask();
+ }
+
+ @Override
+ public void updateTask() {
+ homunculus.getLookHelper().setLookPosition(dominant.posX, dominant.posY + (double) dominant.getEyeHeight(),
+ dominant.posZ, (float) homunculus.getHorizontalFaceSpeed(), (float) homunculus.getVerticalFaceSpeed());
+ }
+}
diff --git a/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java b/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java
index 9c60a75..33d07ec 100644
--- a/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java
+++ b/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java
@@ -24,6 +24,8 @@ public class EntityHomunculus extends EntityCreature {
private static final Skin FALLBACK_SKIN = new FallbackSkin();
private Skin skin;
+ private boolean masochism;
+
public EntityHomunculus(World world) {
super(world);
getDataManager().register(SKIN_SOURCE, new NBTTagCompound());
@@ -33,6 +35,9 @@ public class EntityHomunculus extends EntityCreature {
@Override
protected void entityInit() {
super.entityInit();
+ if (getRNG().nextInt(70) == 0) {
+ masochism = true;
+ }
}
@Override
@@ -40,6 +45,7 @@ public class EntityHomunculus extends EntityCreature {
tasks.addTask(0, new EntityAIPanicFire(this, 0.7));
tasks.addTask(1, new EntityAISwimming(this));
tasks.addTask(2, new EntityAIWatchLeashHolder(this));
+ tasks.addTask(3, new EntityAIMasochism(this, 0.5, 15.0F));
}
private boolean isPlayerProfileUpdated(GameProfile a, GameProfile b) {
@@ -122,6 +128,7 @@ public class EntityHomunculus extends EntityCreature {
this.getDataManager().set(SKIN_SOURCE, ownerCompound);
}
}
+ masochism = compound.getBoolean("Masochism");
}
@Override
@@ -149,6 +156,13 @@ public class EntityHomunculus extends EntityCreature {
} else if (compound.hasKey("SkinSource")) {
compound.removeTag("SkinSource");
}
+ if (masochism) {
+ compound.setBoolean("Masochism", masochism);
+ }
return compound;
}
+
+ public boolean isMasochist() {
+ return masochism;
+ }
}