From bf84d197228ea6f91be4615297175e41f1b3dd26 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 8 Aug 2021 20:08:26 +0200 Subject: [PATCH] Fixed the shotgun creeper bug --- .../entity/behaviour/CreeperBehaviour.java | 20 ++++++++++++++++++- .../entity/behaviour/EntityBehaviour.java | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java index 36da18ab..97241c6c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java @@ -4,16 +4,34 @@ import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import net.minecraft.entity.mob.CreeperEntity; +import net.minecraft.util.math.MathHelper; public class CreeperBehaviour extends EntityBehaviour { @Override public void update(Caster source, CreeperEntity entity, DisguiseSpell spell) { - if (isSneakingOnGround(source)) { + int fuseCountDown = spell.getDisguise().getOrCreateTag().getInt("fuseCountdown"); + + boolean trigger = isSneakingOnGround(source); + + if (trigger) { + fuseCountDown++; + } else if (fuseCountDown > 0) { + fuseCountDown--; + } + + int max = source.isClient() ? 90 : 30; + + fuseCountDown = MathHelper.clamp(fuseCountDown, 0, max + 1); + + if (fuseCountDown <= max && trigger) { entity.setFuseSpeed(1); } else { entity.setFuseSpeed(-1); entity.setTarget(null); entity.getVisibilityCache().clear(); } + + System.out.println(fuseCountDown); + spell.getDisguise().getOrCreateTag().putInt("fuseCountdown", fuseCountDown); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index 8a7007d6..90ff0a54 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -168,6 +168,7 @@ public class EntityBehaviour { to.horizontalSpeed = from.horizontalSpeed; to.prevHorizontalSpeed = from.prevHorizontalSpeed; to.setOnGround(from.isOnGround()); + to.setInvulnerable(from.isInvulnerable() || (from instanceof PlayerEntity && ((PlayerEntity)from).getAbilities().creativeMode)); to.distanceTraveled = from.distanceTraveled; @@ -248,7 +249,7 @@ public class EntityBehaviour { protected boolean isSneakingOnGround(Caster source) { Entity e = source.getEntity(); - return e.isSneaking() && (e.isOnGround() || !(e instanceof PlayerEntity && ((PlayerEntity)e).getAbilities().flying)); + return e.isSneaking() && (e.isOnGround() && !(e instanceof PlayerEntity && ((PlayerEntity)e).getAbilities().flying)); } public static void register(Supplier> behaviour, EntityType... types) {