1
1
package com .insane96mcp .shieldsplus .world .item .enchantment ;
2
2
3
+ import insane96mcp .insanelib .util .MCUtils ;
4
+ import net .minecraft .core .particles .ParticleTypes ;
5
+ import net .minecraft .nbt .CompoundTag ;
6
+ import net .minecraft .sounds .SoundEvents ;
7
+ import net .minecraft .util .Mth ;
8
+ import net .minecraft .world .damagesource .DamageSource ;
3
9
import net .minecraft .world .entity .EquipmentSlot ;
10
+ import net .minecraft .world .entity .LivingEntity ;
11
+ import net .minecraft .world .entity .ai .attributes .AttributeModifier ;
12
+ import net .minecraft .world .entity .player .Player ;
13
+ import net .minecraft .world .item .ItemStack ;
14
+ import net .minecraft .world .item .ShieldItem ;
4
15
import net .minecraft .world .item .enchantment .Enchantment ;
5
16
import net .minecraft .world .item .enchantment .EnchantmentCategory ;
17
+ import net .minecraft .world .phys .AABB ;
18
+ import net .minecraftforge .common .ForgeMod ;
19
+ import org .jetbrains .annotations .NotNull ;
20
+
21
+ import java .util .List ;
22
+ import java .util .UUID ;
6
23
7
24
public class ShieldBashEnchantment extends Enchantment {
8
25
9
26
public ShieldBashEnchantment () {
10
27
super (Rarity .VERY_RARE , EnchantmentCategory .BREAKABLE , new EquipmentSlot []{EquipmentSlot .MAINHAND , EquipmentSlot .OFFHAND });
11
28
}
12
29
13
- public int getMinCost (int p_44598_ ) {
14
- return 22 ;
30
+ public int getMinCost (int level ) {
31
+ return 25 ;
15
32
}
16
33
17
- public int getMaxCost (int p_44600_ ) {
18
- return this .getMinCost (p_44600_ ) + 22 ;
34
+ public int getMaxCost (int level ) {
35
+ return this .getMinCost (level ) + 22 ;
19
36
}
20
37
21
38
public int getMaxLevel () {
@@ -26,4 +43,70 @@ public int getMaxLevel() {
26
43
public boolean isTreasureOnly () {
27
44
return true ;
28
45
}
46
+
47
+ @ Override
48
+ public boolean canEnchant (ItemStack stack ) {
49
+ return stack .getItem () instanceof ShieldItem ;
50
+ }
51
+
52
+ @ Override
53
+ public boolean checkCompatibility (@ NotNull Enchantment enchantment ) {
54
+ return !(enchantment instanceof ShieldReflectionEnchantment ) && !(enchantment instanceof ShieldRecoilEnchantment ) && super .checkCompatibility (enchantment );
55
+ }
56
+
57
+ public static void onTick (Player player ) {
58
+ CompoundTag tag = player .getPersistentData ();
59
+ if (player .isBlocking () && tag .getByte ("shield_bashing" ) <= 0 ) {
60
+ if (tag .getByte ("bash_timer" ) < 30 ) {
61
+ tag .putByte ("bash_timer" , (byte ) (tag .getByte ("bash_timer" ) + 1 ));
62
+ if (tag .getByte ("bash_timer" ) >= 30 )
63
+ player .playSound (SoundEvents .SHIELD_BLOCK , 1f , 1.65f );
64
+ }
65
+ else if (player .isCrouching () && player .isOnGround ()) {
66
+ //player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 10, 10, true, true, false));
67
+ tag .putByte ("shield_bashing" , (byte ) 12 );
68
+ MCUtils .applyModifier (player , ForgeMod .STEP_HEIGHT_ADDITION .get (), UUID .fromString ("259f26e7-6914-4856-a01f-8b2295e6d244" ), "Shield Bash step height" , 0.6d , AttributeModifier .Operation .ADDITION , false );
69
+ float f = -Mth .sin (player .getYRot () * ((float ) Math .PI / 180F ));
70
+ float f1 = Mth .cos (player .getYRot () * ((float ) Math .PI / 180F ));
71
+ player .playSound (SoundEvents .SHIELD_BLOCK , 1f , 2.0f );
72
+ player .setDeltaMovement (player .getDeltaMovement ().add (f * 2.75d , 0.4d , f1 * 2.75d ));
73
+ for (int i = 0 ; i < 50 ; i ++) {
74
+ player .level .addParticle (ParticleTypes .CLOUD , player .getX () + Mth .nextDouble (player .getRandom (), -0.5d , 0.5d ), player .getY () + Mth .nextDouble (player .getRandom (), -0.5d , 0.5d ) + 0.9d , player .getZ () + Mth .nextDouble (player .getRandom (), -0.5d , 0.5d ), 0.1 , 0 , 0.1 );
75
+ }
76
+ tag .putByte ("bash_timer" , (byte ) -30 );
77
+ }
78
+ }
79
+ else if (tag .getByte ("bash_timer" ) > 30 ){
80
+ tag .putByte ("bash_timer" , (byte ) 0 );
81
+ }
82
+ else {
83
+ tag .putByte ("bash_timer" , (byte ) (tag .getByte ("bash_timer" ) + 1 ));
84
+ }
85
+
86
+ if (tag .getByte ("shield_bashing" ) > 0 ) {
87
+ tag .putByte ("shield_bashing" , (byte ) (tag .getByte ("shield_bashing" ) - 1 ));
88
+ if (tag .getByte ("shield_bashing" ) == 0 ) {
89
+ if (player .getAttribute (ForgeMod .STEP_HEIGHT_ADDITION .get ()) != null )
90
+ //noinspection ConstantConditions
91
+ player .getAttribute (ForgeMod .STEP_HEIGHT_ADDITION .get ()).removeModifier (UUID .fromString ("259f26e7-6914-4856-a01f-8b2295e6d244" ));
92
+ }
93
+ if (player .isBlocking ()) {
94
+ damageAndKnockback (player );
95
+ }
96
+ }
97
+ }
98
+
99
+ public static void damageAndKnockback (Player player ) {
100
+ AABB aabb = player .getBoundingBox ().inflate (1.25d , 0.5d , 1.25d );
101
+ List <LivingEntity > entities = player .level .getEntitiesOfClass (LivingEntity .class , aabb , entity -> entity != player );
102
+ for (LivingEntity entity : entities ) {
103
+ if (entity .isDeadOrDying () || entity .invulnerableTime > 10 )
104
+ continue ;
105
+ entity .knockback (1.5d , player .getX () - entity .getX (), player .getZ () - entity .getZ ());
106
+ if (entity .hurt (DamageSource .playerAttack (player ), 5 )) {
107
+ player .playSound (SoundEvents .SHIELD_BLOCK , 1.0f , 0.5f );
108
+ ShieldAblazeEnchantment .apply (player , entity );
109
+ }
110
+ }
111
+ }
29
112
}
0 commit comments