From 8408acffa12c65ef5690c153ffd0e0be962d1045 Mon Sep 17 00:00:00 2001 From: citrons Date: Mon, 6 Nov 2023 14:47:46 -0600 Subject: homunculi may be "variant" --- .../homunculus/EntityAIMasochism.java | 63 ++++++++++++++++++++++ .../mondecitronne/homunculus/EntityHomunculus.java | 14 +++++ 2 files changed, 77 insertions(+) create mode 100644 src/main/java/com/mondecitronne/homunculus/EntityAIMasochism.java 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; + } } -- cgit v1.2.3