From 79e1ece6421658ebb9d44f30fbeef96607cbe17d Mon Sep 17 00:00:00 2001 From: Pug <81167232+MerchantPug@users.noreply.github.com> Date: Sun, 19 May 2024 08:53:33 +1000 Subject: [PATCH] Fix Key Pressed with continuous keys. --- CHANGELOG.md | 4 +- .../apugli/powers/bugfix/key_pressed.json | 54 +++++++++++++++++++ .../apugli/client/ApugliClientFabric.java | 7 +-- .../client/ApugliForgeClientEventHandler.java | 4 +- 4 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 Common/src/test/resources/data/apugli/powers/bugfix/key_pressed.json diff --git a/CHANGELOG.md b/CHANGELOG.md index af911279..1673032e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,4 @@ ## Bugfixes -- Fixed `damage_nearby_x_hit` power type running attacker, target bientity conditions without an attacker. ([toomanyorigins#87](https://github.com/MerchantPug/toomanyorigins/issues/87)) \ No newline at end of file +- Fixed `damage_nearby_x_hit` power type running attacker, target bientity conditions without an attacker. ([toomanyorigins#87](https://github.com/MerchantPug/toomanyorigins/issues/87)) +- Fixed Explosion Sync packet desync. Which should affect the `apugli:explode` and `explosion_raycast` entity action types, and the `rocket_jump` power type. +- Fixed `key_pressed` entity condition type not functioning properly with `continuous` keys. \ No newline at end of file diff --git a/Common/src/test/resources/data/apugli/powers/bugfix/key_pressed.json b/Common/src/test/resources/data/apugli/powers/bugfix/key_pressed.json new file mode 100644 index 00000000..00c44f2d --- /dev/null +++ b/Common/src/test/resources/data/apugli/powers/bugfix/key_pressed.json @@ -0,0 +1,54 @@ +{ + "type": "apoli:action_over_time", + "interval": 1, + "entity_action": { + "type": "apugli:explode", + "power": 5, + "damage_self": false + }, + "condition": { + "type": "apoli:and", + "conditions": [ + { + "type": "apoli:or", + "conditions": [ + { + "type": "apoli:block_collision", + "offset_x": 1.5 + }, + { + "type": "apoli:block_collision", + "offset_x": -1.5 + }, + { + "type": "apoli:block_collision", + "offset_y": 1.5 + }, + { + "type": "apoli:block_collision", + "offset_y": -1.5 + }, + { + "type": "apoli:block_collision", + "offset_z": 1.5 + }, + { + "type": "apoli:block_collision", + "offset_z": -1.5 + } + ] + }, + { + "type": "apoli:fall_flying" + }, + { + "type": "apugli:key_pressed", + "key": { + "key": "key.use", + "continous": true + } + } + ] + }, + "hidden": true +} \ No newline at end of file diff --git a/Fabric/src/main/java/net/merchantpug/apugli/client/ApugliClientFabric.java b/Fabric/src/main/java/net/merchantpug/apugli/client/ApugliClientFabric.java index f00d2559..0d7ce826 100644 --- a/Fabric/src/main/java/net/merchantpug/apugli/client/ApugliClientFabric.java +++ b/Fabric/src/main/java/net/merchantpug/apugli/client/ApugliClientFabric.java @@ -4,17 +4,14 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientEntityEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents; import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; -import net.fabricmc.loader.api.FabricLoader; import net.merchantpug.apugli.client.renderer.CustomProjectileRenderer; import net.merchantpug.apugli.client.util.TextureUtilClient; import net.merchantpug.apugli.component.ApugliEntityComponents; import net.merchantpug.apugli.component.KeyPressComponent; import net.merchantpug.apugli.condition.factory.entity.CachedBlockInRadiusCondition; -import net.merchantpug.apugli.integration.pehkui.PehkuiUtil; import net.merchantpug.apugli.mixin.fabric.client.accessor.ApoliClientAccessor; import net.merchantpug.apugli.network.ApugliPackets; import net.merchantpug.apugli.network.c2s.UpdateKeysPressedPacket; @@ -70,12 +67,12 @@ public static void handleActiveKeys(Minecraft minecraft) { if (!currentKeyBindingStates.containsKey(key.key)) { currentKeyBindingStates.put(key.key, keyBinding.isDown()); } - if (currentKeyBindingStates.get(key.key) && (key.continuous || !lastKeyBindingStates.getOrDefault(key.key, false))) { + if (currentKeyBindingStates.getOrDefault(key.key, false) && (key.continuous || !lastKeyBindingStates.getOrDefault(key.key, false))) { component.addKey(key); if (!lastKeyBindingStates.getOrDefault(key.key, false)) { addedKeys.add(key); } - } else if ((!currentKeyBindingStates.get(key.key) || !key.continuous) && lastKeyBindingStates.getOrDefault(key.key, false)) { + } else if (!currentKeyBindingStates.getOrDefault(key.key, false) && lastKeyBindingStates.getOrDefault(key.key, false)) { component.removeKey(key); removedKeys.add(key); } diff --git a/Forge/src/main/java/net/merchantpug/apugli/client/ApugliForgeClientEventHandler.java b/Forge/src/main/java/net/merchantpug/apugli/client/ApugliForgeClientEventHandler.java index f3b373ad..50587a3b 100644 --- a/Forge/src/main/java/net/merchantpug/apugli/client/ApugliForgeClientEventHandler.java +++ b/Forge/src/main/java/net/merchantpug/apugli/client/ApugliForgeClientEventHandler.java @@ -73,12 +73,12 @@ public static void handleActiveKeys() { if (!currentKeyBindingStates.containsKey(key.key())) { currentKeyBindingStates.put(key.key(), keyBinding.isDown()); } - if (currentKeyBindingStates.get(key.key()) && (key.continuous() || !lastKeyBindingStates.getOrDefault(key.key(), false))) { + if (currentKeyBindingStates.getOrDefault(key.key(), false) && (key.continuous() || !lastKeyBindingStates.getOrDefault(key.key(), false))) { capability.addKey(key); if (!lastKeyBindingStates.getOrDefault(key.key(), false)) { addedKeys.add(key); } - } else if ((!currentKeyBindingStates.get(key.key()) || !key.continuous()) && lastKeyBindingStates.getOrDefault(key.key(), false)) { + } else if (!currentKeyBindingStates.getOrDefault(key.key(), false) && lastKeyBindingStates.getOrDefault(key.key(), false)) { capability.removeKey(key); removedKeys.add(key); }