Optimizations

Optimized jetpack usage check
This commit is contained in:
Konhaiii 2025-06-08 10:19:06 +02:00
parent b682a7e03d
commit 951e6854ac
2 changed files with 42 additions and 38 deletions

View file

@ -10,7 +10,7 @@ loader_version=0.16.14
loom_version=1.10-SNAPSHOT loom_version=1.10-SNAPSHOT
# Mod Properties # Mod Properties
mod_version=1.0.3 mod_version=1.0.4
maven_group=konhaiii.powered_jetpacks maven_group=konhaiii.powered_jetpacks
archives_base_name=powered_jetpacks archives_base_name=powered_jetpacks

View file

@ -28,47 +28,51 @@ public abstract class ClientPlayerEntityMixin {
@Inject(method = "tick", at = @At("HEAD")) @Inject(method = "tick", at = @At("HEAD"))
private void onTick(CallbackInfo ci) { private void onTick(CallbackInfo ci) {
ClientPlayerEntity player = (ClientPlayerEntity) (Object) this; ClientPlayerEntity player = (ClientPlayerEntity) (Object) this;
ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST); if (player.input.jumping) {
ItemStack backStack = ItemStack.EMPTY; ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST);
ItemStack backStack = ItemStack.EMPTY;
if (PoweredJetpacks.isTrinketsLoaded) { if (PoweredJetpacks.isTrinketsLoaded) {
try { try {
Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer"); Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer");
Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class); Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class);
backStack = (ItemStack) getBackStackMethod.invoke(null, player); backStack = (ItemStack) getBackStackMethod.invoke(null, player);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) { IllegalAccessException e) {
PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class."); PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class.");
}
} }
}
ItemStack jetpackStack = null; ItemStack jetpackStack = null;
if (isValidJetpack(chestStack)) { if (isValidJetpack(chestStack)) {
jetpackStack = chestStack; jetpackStack = chestStack;
} else if (isValidJetpack(backStack)) { } else if (isValidJetpack(backStack)) {
jetpackStack = backStack; jetpackStack = backStack;
} }
if (jetpackStack != null && player.input.jumping) { if (jetpackStack != null) {
PacketByteBuf buf = PacketByteBufs.create(); PacketByteBuf buf = PacketByteBufs.create();
JetpackItem jetpack = (JetpackItem) jetpackStack.getItem(); JetpackItem jetpack = (JetpackItem) jetpackStack.getItem();
Vec3d velocity = player.getVelocity(); Vec3d velocity = player.getVelocity();
float horizontalBoost = jetpack.getFlightSpeed(); float horizontalBoost = jetpack.getFlightSpeed();
player.setVelocity( player.setVelocity(
velocity.x + (player.getRotationVector().x * horizontalBoost), velocity.x + (player.getRotationVector().x * horizontalBoost),
jetpack.addToVerticalVelocity(player.getVelocity().y), jetpack.addToVerticalVelocity(player.getVelocity().y),
velocity.z + (player.getRotationVector().z * horizontalBoost) velocity.z + (player.getRotationVector().z * horizontalBoost)
); );
player.fallDistance = 0; player.fallDistance = 0;
soundCounter++; soundCounter++;
if (soundCounter >= 8) { if (soundCounter >= 8) {
JetpackPacket.encode(new JetpackPacket(true), buf); JetpackPacket.encode(new JetpackPacket(true), buf);
soundCounter = 0; soundCounter = 0;
} else { } else {
JetpackPacket.encode(new JetpackPacket(false), buf); JetpackPacket.encode(new JetpackPacket(false), buf);
}
ClientPlayNetworking.send(JetpackPacket.getPacketId(), buf);
} else if (soundCounter != 8) {
soundCounter = 8;
} }
ClientPlayNetworking.send(JetpackPacket.getPacketId(), buf);
} else if (soundCounter != 8) { } else if (soundCounter != 8) {
soundCounter = 8; soundCounter = 8;
} }