Add `minimumBoostTicks`

This commit is contained in:
Brady 2023-06-23 16:30:10 -07:00
parent c10903be69
commit f56e0569a2
No known key found for this signature in database
GPG Key ID: 73A788379A197567
1 changed files with 32 additions and 8 deletions

View File

@ -60,7 +60,19 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
// :sunglasses: // :sunglasses:
private final NetherPathfinderContext context; private final NetherPathfinderContext context;
private final PathManager pathManager; private final PathManager pathManager;
/**
* Remaining cool-down ticks between firework usage
*/
private int remainingFireworkTicks; private int remainingFireworkTicks;
/**
* The most recent minimum number of firework boost ticks, equivalent to {@code 10 * (1 + Flight)}
* <p>
* Updated every time a firework is automatically used
*/
private int minimumBoostTicks;
private int remainingSetBackTicks; private int remainingSetBackTicks;
private BlockStateInterface bsi; private BlockStateInterface bsi;
@ -561,6 +573,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
} }
logDirect("attempting to use firework" + (forceUseFirework ? " takeoff" : "")); logDirect("attempting to use firework" + (forceUseFirework ? " takeoff" : ""));
ctx.playerController().processRightClick(ctx.player(), ctx.world(), EnumHand.MAIN_HAND); ctx.playerController().processRightClick(ctx.player(), ctx.world(), EnumHand.MAIN_HAND);
this.minimumBoostTicks = 10 * (1 + getFireworkBoost(ctx.player().getHeldItemMainhand()).orElse(0));
this.remainingFireworkTicks = 10; this.remainingFireworkTicks = 10;
} }
} }
@ -576,7 +589,7 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
this.path = ElytraBehavior.this.pathManager.getPath(); this.path = ElytraBehavior.this.pathManager.getPath();
this.playerNear = ElytraBehavior.this.pathManager.getNear(); this.playerNear = ElytraBehavior.this.pathManager.getNear();
this.start = ElytraBehavior.this.ctx.playerFeetAsVec(); this.start = ElytraBehavior.this.ctx.playerFeetAsVec();
this.isBoosted = ElytraBehavior.this.isFireworkActive(); this.isBoosted = ElytraBehavior.this.getAttachedFirework().isPresent();
} }
@Override @Override
@ -618,19 +631,30 @@ public final class ElytraBehavior extends Behavior implements IElytraBehavior, H
return false; return false;
} }
// If it has NBT data, make sure it won't cause us to explode. // If it has NBT data, make sure it won't cause us to explode.
final NBTTagCompound subCompound = itemStack.getSubCompound("Fireworks"); final NBTTagCompound compound = itemStack.getSubCompound("Fireworks");
return subCompound == null || !subCompound.hasKey("Explosions"); return compound == null || !compound.hasKey("Explosions");
} }
private static boolean isBoostingFireworks(final ItemStack itemStack) { private static boolean isBoostingFireworks(final ItemStack itemStack) {
final NBTTagCompound subCompound = itemStack.getSubCompound("Fireworks"); return getFireworkBoost(itemStack).isPresent();
return isFireworks(itemStack) && subCompound != null && subCompound.hasKey("Flight");
} }
private boolean isFireworkActive() { private static OptionalInt getFireworkBoost(final ItemStack itemStack) {
if (isFireworks(itemStack)) {
final NBTTagCompound compound = itemStack.getSubCompound("Fireworks");
if (compound != null && compound.hasKey("Flight")) {
return OptionalInt.of(compound.getByte("Flight"));
}
}
return OptionalInt.empty();
}
private Optional<EntityFireworkRocket> getAttachedFirework() {
return ctx.world().loadedEntityList.stream() return ctx.world().loadedEntityList.stream()
.filter(x -> x instanceof EntityFireworkRocket) .filter(x -> x instanceof EntityFireworkRocket)
.anyMatch(x -> Objects.equals(((IEntityFireworkRocket) x).getBoostedEntity(), ctx.player())); .filter(x -> Objects.equals(((IEntityFireworkRocket) x).getBoostedEntity(), ctx.player()))
.map(x -> (EntityFireworkRocket) x)
.findFirst();
} }
private boolean isHitboxClear(final Vec3d start, final Vec3d dest, final Double growAmount, boolean ignoreLava) { private boolean isHitboxClear(final Vec3d start, final Vec3d dest, final Double growAmount, boolean ignoreLava) {