From 951e6854acbc8086c130bd08f24820b261b7f8f4 Mon Sep 17 00:00:00 2001 From: Konhaiii Date: Sun, 8 Jun 2025 10:19:06 +0200 Subject: [PATCH] Optimizations Optimized jetpack usage check --- gradle.properties | 2 +- .../mixin/client/ClientPlayerEntityMixin.java | 78 ++++++++++--------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0cdb2ab..0daee4e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ loader_version=0.16.14 loom_version=1.10-SNAPSHOT # Mod Properties -mod_version=1.0.3 +mod_version=1.0.4 maven_group=konhaiii.powered_jetpacks archives_base_name=powered_jetpacks diff --git a/src/client/java/konhaiii/powered_jetpacks/mixin/client/ClientPlayerEntityMixin.java b/src/client/java/konhaiii/powered_jetpacks/mixin/client/ClientPlayerEntityMixin.java index da42c8a..f2c50d0 100644 --- a/src/client/java/konhaiii/powered_jetpacks/mixin/client/ClientPlayerEntityMixin.java +++ b/src/client/java/konhaiii/powered_jetpacks/mixin/client/ClientPlayerEntityMixin.java @@ -28,47 +28,51 @@ public abstract class ClientPlayerEntityMixin { @Inject(method = "tick", at = @At("HEAD")) private void onTick(CallbackInfo ci) { ClientPlayerEntity player = (ClientPlayerEntity) (Object) this; - ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST); - ItemStack backStack = ItemStack.EMPTY; + if (player.input.jumping) { + ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST); + ItemStack backStack = ItemStack.EMPTY; - if (PoweredJetpacks.isTrinketsLoaded) { - try { - Class optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer"); - Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class); - backStack = (ItemStack) getBackStackMethod.invoke(null, player); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException e) { - PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class."); + if (PoweredJetpacks.isTrinketsLoaded) { + try { + Class optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer"); + Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class); + backStack = (ItemStack) getBackStackMethod.invoke(null, player); + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | + IllegalAccessException e) { + PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class."); + } } - } - ItemStack jetpackStack = null; - if (isValidJetpack(chestStack)) { - jetpackStack = chestStack; - } else if (isValidJetpack(backStack)) { - jetpackStack = backStack; - } - - if (jetpackStack != null && player.input.jumping) { - PacketByteBuf buf = PacketByteBufs.create(); - JetpackItem jetpack = (JetpackItem) jetpackStack.getItem(); - Vec3d velocity = player.getVelocity(); - float horizontalBoost = jetpack.getFlightSpeed(); - player.setVelocity( - velocity.x + (player.getRotationVector().x * horizontalBoost), - jetpack.addToVerticalVelocity(player.getVelocity().y), - velocity.z + (player.getRotationVector().z * horizontalBoost) - ); - player.fallDistance = 0; - - soundCounter++; - if (soundCounter >= 8) { - JetpackPacket.encode(new JetpackPacket(true), buf); - soundCounter = 0; - } else { - JetpackPacket.encode(new JetpackPacket(false), buf); + ItemStack jetpackStack = null; + if (isValidJetpack(chestStack)) { + jetpackStack = chestStack; + } else if (isValidJetpack(backStack)) { + jetpackStack = backStack; + } + + if (jetpackStack != null) { + PacketByteBuf buf = PacketByteBufs.create(); + JetpackItem jetpack = (JetpackItem) jetpackStack.getItem(); + Vec3d velocity = player.getVelocity(); + float horizontalBoost = jetpack.getFlightSpeed(); + player.setVelocity( + velocity.x + (player.getRotationVector().x * horizontalBoost), + jetpack.addToVerticalVelocity(player.getVelocity().y), + velocity.z + (player.getRotationVector().z * horizontalBoost) + ); + player.fallDistance = 0; + + soundCounter++; + if (soundCounter >= 8) { + JetpackPacket.encode(new JetpackPacket(true), buf); + soundCounter = 0; + } else { + 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) { soundCounter = 8; }