Fixed the shotgun creeper bug

This commit is contained in:
Sollace 2021-08-08 20:08:26 +02:00
parent 82a315510e
commit bf84d19722
2 changed files with 21 additions and 2 deletions

View file

@ -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<CreeperEntity> {
@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);
}
}

View file

@ -168,6 +168,7 @@ public class EntityBehaviour<T extends Entity> {
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<T extends Entity> {
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 <T extends Entity> void register(Supplier<EntityBehaviour<T>> behaviour, EntityType<?>... types) {