[TUTORIAL] How to add a parry shield

Started by TiberiumTree on

Topic category: User side tutorials

Last seen on 10:02, 8. Aug 2023
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] How to add a parry shield

This tutorial brings Dark Souls' parry shield into Minecraft,

.......but without durability setting option.

sword and shield

 

1.The food shield

food visual

Food properties

Although it seemed pretty weird that a shield is a kind of food, trigger On player stopped using does not work on tools and items, and I don't know how to write java code to use that trigger, there is no other choice.

tag

Player finishes using item

This global trigger prevents players from eating up their shield after holding it 9999 ticks.

food trigger

set right-click to defend, and external custom key to parry.

ShieldValue recovers as shield time increases and absorbs equal value damage via global trigger setting.

reset value after using

When the player stops using the shield, the ShieldTick and ShieldValue reset.

 

2.Defence and Parry procedure

normal defence

Part1

Axes can not cool down this shield as vanilla ones, to make up, they can deal 1.5 times damage to ShieldValue.

x1y1z1 is the directional vector for the attacked player, and x2y2z2 is the directional vector for attacker or arrows.

Ranged items are not always facing forward, so the velocity vector is better for judging the incoming direction of the attack.

 

Part2

vector angle

cos 135°≈ -0.707106.

Angle of the vector determines whether a defence is successful.

Besides, this can be used not only for shields blocking attacks but also for weapons backstabbing, just reverse the >.

simplify 1

Ignoring the pitch simplifies the calculation relative to the Y-axis

simplify 2

Considering the case of yaw as only 2 kinds, face and back, more calculation can be simplified.

 

 

If the defence is successful, cancel the trigger, and if ShieldValue drops to 0 or below, punish the shield-bearer.

 

parry

Parry procedure is similar to normal defence procedure. 

 

3.Shield overlay

overlay

As ShieldValue is invisible to the player, they need HUD to keep a handle on the situation.