Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sword blocking animation #769

Open
lowercasebtw opened this issue Nov 1, 2024 · 15 comments
Open

Sword blocking animation #769

lowercasebtw opened this issue Nov 1, 2024 · 15 comments
Labels
enhancement A feature or enhancement suggestion for OldCombatMechanics

Comments

@lowercasebtw
Copy link

Now that 1.21.2 has come out and split the food component into two, food and consumable. The consumable component has a field named animation which allows you to specify the animation played when using said item, one of those animations being "block". Currently tho in 1.21.2/3, it only shows the blocking animation in third person but I reported the first person animation missing as a bug (https://bugs.mojang.com/browse/MC-275917) and it has been fixed and the first person animation has been introduced into 24w44a.

image

Yall should add a option/abandon using the shield as the way of blocking and instead give the swords the new consumable component with the animation of "block" and consume seconds of 3600 (same time as it was hardcoded in 1.8)

@lowercasebtw lowercasebtw added the enhancement A feature or enhancement suggestion for OldCombatMechanics label Nov 1, 2024
@lowercasebtw
Copy link
Author

Also cool side note, they fixed this bug: https://bugs.mojang.com/browse/MC-152728
This now fixes/reintroduced sprint resetting

@lowercasebtw

This comment was marked as spam.

@notwhitebear
Copy link

This is currently difficult to achieve, ProtocolLib still can't be loaded on 1.21.4 server. I made a plugin to implement this animation just now. (but it can't reduce damage)
plugin.zip
here is the plugin, it depends on Nbt API.

src:
src.zip
feel free to use it.

@kernitus
Copy link
Owner

Now that 1.21.2 has come out and split the food component into two, food and consumable. The consumable component has a field named animation which allows you to specify the animation played when using said item, one of those animations being "block". Currently tho in 1.21.2/3, it only shows the blocking animation in third person but I reported the first person animation missing as a bug (https://bugs.mojang.com/browse/MC-275917) and it has been fixed and the first person animation has been introduced into 24w44a.

image

Yall should add a option/abandon using the shield as the way of blocking and instead give the swords the new consumable component with the animation of "block" and consume seconds of 3600 (same time as it was hardcoded in 1.8)

That only seems to deal with the animation, but we use the shield because it genuinely does block damage, we just configure by how much. How could we ever tell if the damage was meant to be blocked or not otherwise?

@kernitus kernitus changed the title Consumable Block Animation Sword blocking animation Dec 24, 2024
@lowercasebtw
Copy link
Author

lowercasebtw commented Dec 26, 2024

By checking if the current use item has consumable of type block & has the custom data field of whatever to check if it is a OCM blocking tool/is a sword?

@lowercasebtw
Copy link
Author

lowercasebtw commented Dec 26, 2024

There is many ways to check if you are blocking as the consumable thing makes the sword act as a BLOCKING item like shield, so you should be able to do like "isBlocking" or whatever spigot/paper method is and do the custom reduced damage or whatever

@kernitus
Copy link
Owner

There is many ways to check if you are blocking as the consumable thing makes the sword act as a BLOCKING item like shield, so you should be able to do like "isBlocking" or whatever spigot/paper method is and do the custom reduced damage or whatever

That's assuming the client sends packets with the blocking bit set. Also does this mean we have to modify all sword to have the animation property? Because OCM does not modify any items and this is deliberate, because it leads to a nightmare of tracking what items were changed when, and what happens if you uninstall the plugin. It's the same reason we don't edit the attack damage labels on the items directly.

@jtJava
Copy link

jtJava commented Jan 9, 2025

I think it should be on the server to provide players with consumable swords, OCM should just handle the functionality of halving damage if blocking with a sword. AFAIK the server will still register them as "using" the sword, and can be detected by OCM.

@YOMA8338
Copy link

When I asked Copilot in Windows 11 how to halve the damage when right-clicking with a sword, he suggested the following code.
code
Looking at the suggested code and my attempts to create a SwordBlockingPlugin on my own, it appears that I can find out the amount of damage without using a shield.
but In the end, I could not use the copilot to create the code, nor could I create my own code.
sorry

@lowercasebtw
Copy link
Author

lowercasebtw commented Jan 24, 2025

So uhm, I know you mentioned not wanting to add components to items cause of uninstalling the plugin

But as of 25w04a, they added a shield component which would allow you to put the blocking logic entirely in the component.
Its the same component the shield uses for blocking/etc so it is also detectable via the server. But you wouldn't even need to detect it as the component would do the blocking halfing of damage logic for you. Example:

/give @s iron_sword[blocks_attacks={disable_cooldown_scale:0,damage_reductions:[{base:-0.5,factor:0.5}],item_damage:{threshold:0,base:0,factor:0},block_sound:"minecraft:entity.player.hurt"}]

@lowercasebtw
Copy link
Author

lowercasebtw commented Jan 24, 2025

Also the cool thing about this new component is you can finally remove the stupid hardcoded 5 tick delay when blocking!
(the "block_delay_seconds" field, by default is 0 but on the shield is 0.25 (5 ticks))

@deslunes
Copy link

deslunes commented Feb 1, 2025

Hello ! I'm really interested in the new blocks_attack component because it is much more responsive for high ping players. When OldCombatMechanics adds the shield in the left hand of the player, it's an action made by the server, it's not rare for me to get the shield too late, because I have a high ping.

In the other hand, the blocks_attack component is client side, it removes the need for the plugin to listen to the player right click event or whatever is used to detect when a player right clicks on a sword. But it also removes the damage reduction calculation since it's handled by the component.

But I understand that using components to mimic the sword blocking behavior is problematic because you're actually modifying the item, the behavior would stay even if the plugin is disabled. It would be great to add it behind a flag or a setting in the config.yml file.

I'm not a good java developer so I don't know how it would impact performance, but I would use the onInventoryClick, onInventoryClose, onItemDrop, onPlayerDeath and onPlayerQuit events to remove the component from the item whenever it leaves the player's inventory or when the player disconnects, the component would be added when the player connects or craft/get a sword; thus the component would live only in the player's inventory and be removed whenever it leaves the inventory.

@jorgetoh
Copy link

jorgetoh commented Feb 17, 2025

Now that 1.21.2 has come out and split the food component into two, food and consumable. The consumable component has a field named animation which allows you to specify the animation played when using said item, one of those animations being "block". Currently tho in 1.21.2/3, it only shows the blocking animation in third person but I reported the first person animation missing as a bug (https://bugs.mojang.com/browse/MC-275917) and it has been fixed and the first person animation has been introduced into 24w44a.
image
Yall should add a option/abandon using the shield as the way of blocking and instead give the swords the new consumable component with the animation of "block" and consume seconds of 3600 (same time as it was hardcoded in 1.8)

That only seems to deal with the animation, but we use the shield because it genuinely does block damage, we just configure by how much. How could we ever tell if the damage was meant to be blocked or not otherwise?

Instead of modifying the actual item stack on the server, could we explore using packet manipulation? The server could intercept the packet that sends item information to the client and add the consumable property with the 'block' animation and a consume_seconds value (like 3600 for 1.8 blocking duration). This would allow the client to play the blocking animation without the server having to constantly modify the item itself, potentially improving performance. This also simplifies server-side logic, as the server only needs to check if the item is a sword when sending item data, without needing to validate if the item already has the consumable property. The server would still need to handle the actual damage blocking logic.

@lowercasebtw
Copy link
Author

When 1.21.5 comes out, don't use the consumable component for blocking anymore.

Also packet manipulation could work, but on right click, wouldn't the item update clientside to remove it or no? Also anti cheat support

@jorgetoh
Copy link

jorgetoh commented Mar 5, 2025

When 1.21.5 comes out, don't use the consumable component for blocking anymore.

Also packet manipulation could work, but on right click, wouldn't the item update clientside to remove it or no? Also anti cheat support

If you listen to all the instances where item information is sent to the client and modify the itemstacks accordingly the client has no way of knowing the item is "not real". (Have to skip players on creative mode as creative will override the itemstack with the modified one and make it persistent)

Some time ago I implemented a very basic tool to translate custom item stacks based on the player client language as a proof of concept. https://github.com/jorgetoh/DynamicLang/blob/main/src/main/java/me/jorgetoh/dynamiclang/managers/ItemStackRenamer.java

Obviously, you could argue why having all this overhead when you can just modify the itemstack one time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or enhancement suggestion for OldCombatMechanics
Projects
None yet
Development

No branches or pull requests

7 participants