Optimizations
Optimized jetpack usage check
This commit is contained in:
parent
b682a7e03d
commit
951e6854ac
2 changed files with 42 additions and 38 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue