@@ -317,6 +317,8 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
317
317
protected boolean swinging ;
318
318
protected int swingTime ;
319
319
320
+ protected int damageNearbyMobsTick ;
321
+
320
322
protected int shieldBlockingTick ;
321
323
protected int prevShieldBlockingTick ;
322
324
protected int shieldCooldown ;
@@ -1090,9 +1092,8 @@ protected void doFirstSpawn() {
1090
1092
1091
1093
this .noDamageTicks = 60 ;
1092
1094
1093
- this .sendRecipeList ();
1094
-
1095
1095
this .sendCreativeContents ();
1096
+ this .sendRecipeList ();
1096
1097
1097
1098
for (long index : this .usedChunks .keySet ()) {
1098
1099
int chunkX = Level .getHashX (index );
@@ -1440,7 +1441,7 @@ public boolean setGamemode(int gamemode, boolean clientSide, AdventureSettings n
1440
1441
this .inventory .sendContents (this );
1441
1442
this .inventory .sendHeldItem (this .hasSpawned .values ());
1442
1443
1443
- this .sendCreativeContents ();
1444
+ // this.sendCreativeContents();
1444
1445
}
1445
1446
1446
1447
return true ;
@@ -2027,9 +2028,7 @@ public boolean onUpdate(int currentTick) {
2027
2028
if (chestplate .getId () == Item .ELYTRA ) {
2028
2029
int damage = chestplate .getDamage ();
2029
2030
if (damage < chestplate .getMaxDurability () - 1 ) {
2030
- Enchantment durability = chestplate .getEnchantment (Enchantment .UNBREAKING );
2031
- if (durability == null || durability .getLevel () <= 0 || ThreadLocalRandom .current ().nextInt (100 ) < chestplate .getDamageChance (durability .getLevel ())) {
2032
- chestplate .setDamage (++damage );
2031
+ if (chestplate .hurtAndBreak (1 ) != 0 ) {
2033
2032
inventory .setChestplate (chestplate , true );
2034
2033
}
2035
2034
} else {
@@ -2096,6 +2095,70 @@ public boolean onUpdate(int currentTick) {
2096
2095
} else {
2097
2096
this .swingTime = 0 ;
2098
2097
}
2098
+
2099
+ if (damageNearbyMobsTick > 0 && !isSpectator ()) {
2100
+ damageNearbyMobsTick --;
2101
+
2102
+ for (Entity entity : level .getNearbyEntities (boundingBox , this )) {
2103
+ if (!(entity instanceof EntityLiving )) {
2104
+ continue ;
2105
+ }
2106
+
2107
+ if (entity instanceof Player player && (player .isCreativeLike () || server .getDifficulty () == 0 || !server .getConfiguration ().isPvp () || !level .getGameRules ().getBoolean (GameRule .PVP ))) {
2108
+ continue ;
2109
+ }
2110
+
2111
+ Item item = inventory .getItemInHand ();
2112
+ Enchantment [] enchantments = item .getId () != Item .ENCHANTED_BOOK ? item .getEnchantments () : Enchantment .EMPTY ;
2113
+
2114
+ ItemAttackDamageEvent event = new ItemAttackDamageEvent (item );
2115
+ event .call ();
2116
+ float damage = event .getAttackDamage ();
2117
+
2118
+ float damageBonus = 0 ;
2119
+ for (Enchantment enchantment : enchantments ) {
2120
+ damageBonus += enchantment .getDamageBonus (entity );
2121
+ }
2122
+ damage += Mth .floor (damageBonus );
2123
+
2124
+ Map <DamageModifier , Float > modifiers = new EnumMap <>(DamageModifier .class );
2125
+ modifiers .put (DamageModifier .BASE , damage );
2126
+
2127
+ float knockbackH = EntityDamageByEntityEvent .GLOBAL_KNOCKBACK_H ;
2128
+ float knockbackV = EntityDamageByEntityEvent .GLOBAL_KNOCKBACK_V ;
2129
+ int knockbackEnchant = item .getEnchantmentLevel (Enchantment .KNOCKBACK );
2130
+ if (knockbackEnchant > 0 ) {
2131
+ knockbackH += knockbackEnchant * 0.1f ;
2132
+ knockbackV += knockbackEnchant * 0.1f ;
2133
+ }
2134
+
2135
+ if (!entity .attack (new EntityDamageByEntityEvent (this , entity , DamageCause .ENTITY_ATTACK , modifiers , knockbackH , knockbackV , enchantments ))) {
2136
+ continue ;
2137
+ }
2138
+
2139
+ for (Enchantment enchantment : enchantments ) {
2140
+ enchantment .doPostAttack (item , this , entity , null );
2141
+ }
2142
+
2143
+ if (isSurvivalLike () && item .isTool () && item .useOn (entity )) {
2144
+ if (item .getDamage () > item .getMaxDurability ()) {
2145
+ inventory .setItemInHand (Items .air ());
2146
+ level .addLevelSoundEvent (this , LevelSoundEventPacket .SOUND_BREAK );
2147
+ } else {
2148
+ inventory .setItemInHand (item );
2149
+ }
2150
+ }
2151
+
2152
+ setMotion (getMotion ().multiply (-0.2 ));
2153
+
2154
+ damageNearbyMobsTick = 0 ;
2155
+ setDataFlag (DATA_FLAG_SPIN_ATTACK , false );
2156
+ break ;
2157
+ }
2158
+ } else {
2159
+ damageNearbyMobsTick = 0 ;
2160
+ setDataFlag (DATA_FLAG_SPIN_ATTACK , false );
2161
+ }
2099
2162
}
2100
2163
2101
2164
this .checkTeleportPosition ();
@@ -3340,7 +3403,8 @@ public void onCompletion(Server server) {
3340
3403
case ProtocolInfo .REQUEST_CHUNK_RADIUS_PACKET :
3341
3404
RequestChunkRadiusPacket requestChunkRadiusPacket = (RequestChunkRadiusPacket ) packet ;
3342
3405
ChunkRadiusUpdatedPacket chunkRadiusUpdatePacket = new ChunkRadiusUpdatedPacket ();
3343
- this .chunkRadius = Math .max (4 , Math .min (requestChunkRadiusPacket .radius , this .viewDistance ));
3406
+ this .chunkRadius = Math .max (4 , Math .min (requestChunkRadiusPacket .radius , this .server .getViewDistance ()));
3407
+ this .viewDistance = this .chunkRadius ;
3344
3408
chunkRadiusUpdatePacket .radius = this .chunkRadius ;
3345
3409
this .dataPacket (chunkRadiusUpdatePacket );
3346
3410
break ;
@@ -3620,7 +3684,7 @@ public void onCompletion(Server server) {
3620
3684
}
3621
3685
3622
3686
if (item .onClickAir (this , directionVector )) {
3623
- if (this .isSurvival ()) {
3687
+ if (this .isSurvivalLike ()) {
3624
3688
this .inventory .setItemInHand (item );
3625
3689
}
3626
3690
@@ -3668,8 +3732,9 @@ public void onCompletion(Server server) {
3668
3732
3669
3733
if (target .onInteract (this , item ) && this .isSurvival ()) {
3670
3734
if (item .isTool ()) {
3671
- if (item .useOn (target ) && item .getDamage () >= item .getMaxDurability ()) {
3735
+ if (item .useOn (target ) && item .getDamage () > item .getMaxDurability ()) {
3672
3736
item = Items .air ();
3737
+ level .addLevelSoundEvent (this , LevelSoundEventPacket .SOUND_BREAK );
3673
3738
}
3674
3739
} else {
3675
3740
if (item .count > 1 ) {
@@ -3697,10 +3762,14 @@ public void onCompletion(Server server) {
3697
3762
3698
3763
ItemAttackDamageEvent event = new ItemAttackDamageEvent (item );
3699
3764
this .server .getPluginManager ().callEvent (event );
3765
+
3700
3766
float itemDamage = event .getAttackDamage ();
3767
+
3768
+ float damageBonus = 0 ;
3701
3769
for (Enchantment enchantment : enchantments ) {
3702
- itemDamage += enchantment .getDamageBonus (target );
3770
+ damageBonus += enchantment .getDamageBonus (target );
3703
3771
}
3772
+ itemDamage += Mth .floor (damageBonus );
3704
3773
3705
3774
Map <DamageModifier , Float > damage = new EnumMap <>(DamageModifier .class );
3706
3775
damage .put (DamageModifier .BASE , itemDamage );
@@ -3727,14 +3796,19 @@ public void onCompletion(Server server) {
3727
3796
}
3728
3797
3729
3798
for (Enchantment enchantment : enchantments ) {
3730
- enchantment .doPostAttack (this , target , null );
3799
+ enchantment .doPostAttack (item , this , target , null );
3731
3800
}
3732
3801
3733
3802
if (item .isTool () && this .isSurvivalLike ()) {
3734
- if (item .useOn (target ) && item .getDamage () >= item .getMaxDurability ()) {
3735
- this .inventory .setItemInHand (Item .get (0 ));
3803
+ if (item .useOn (target )) {
3804
+ if (item .getDamage () > item .getMaxDurability ()) {
3805
+ this .inventory .setItemInHand (Item .get (Item .AIR ));
3806
+ level .addLevelSoundEvent (this , LevelSoundEventPacket .SOUND_BREAK );
3807
+ } else {
3808
+ this .inventory .setItemInHand (item );
3809
+ }
3736
3810
} else {
3737
- if (item .getId () == 0 || this .inventory .getItemInHand ().getId () == item .getId ()) {
3811
+ if (item .getId () == Item . AIR || this .inventory .getItemInHand ().getId () == item .getId ()) {
3738
3812
this .inventory .setItemInHand (item );
3739
3813
} else {
3740
3814
server .getLogger ().debug ("Tried to set item " + item .getId () + " but " + this .username + " had item " + this .inventory .getItemInHand ().getId () + " in their hand slot" );
@@ -4493,10 +4567,12 @@ public void kill() {
4493
4567
message = "death.attack.magma" ;
4494
4568
break ;
4495
4569
case FIRE :
4496
- message = "death.attack.onFire" ;
4570
+ case CAMPFIRE :
4571
+ case SOUL_CAMPFIRE :
4572
+ message = "death.attack.inFire" ;
4497
4573
break ;
4498
4574
case FIRE_TICK :
4499
- message = "death.attack.inFire " ;
4575
+ message = "death.attack.onFire " ;
4500
4576
break ;
4501
4577
case DROWNING :
4502
4578
message = "death.attack.drown" ;
@@ -4808,7 +4884,7 @@ public boolean attack(EntityDamageEvent source) {
4808
4884
}
4809
4885
4810
4886
//Critical hit
4811
- if (!damager .onGround && damager instanceof Player player && !damager .hasEffect (Effect .BLINDNESS )) {
4887
+ if (!damager .onGround && damager instanceof Player player && !damager .hasEffect (Effect .BLINDNESS ) && ! damager . isRiding () && ! damager . isInsideOfWater ( false ) ) {
4812
4888
if (player .speed != null && player .speed .y > 0 ) {
4813
4889
if (player .attackCriticalThisJump <= 0 ) {
4814
4890
critical = true ;
@@ -4912,10 +4988,7 @@ protected boolean blockUsingShield(EntityDamageEvent source) {
4912
4988
float damage = source .getDamage ();
4913
4989
if (damage >= 3 ) {
4914
4990
Item shield = itemStack .value ();
4915
- int itemDamage = shield .getDamage () + Mth .floor (damage + 1 );
4916
- if (itemDamage < shield .getMaxDurability ()) {
4917
- shield .setDamage (itemDamage );
4918
- } else {
4991
+ if (shield .hurtAndBreak (Mth .floor (damage ) + 1 ) < 0 ) {
4919
4992
shield .pop ();
4920
4993
level .addLevelSoundEvent (this , LevelSoundEventPacket .SOUND_BREAK );
4921
4994
}
@@ -5824,14 +5897,16 @@ public void startFishing(Item fishingRod) {
5824
5897
* Stop fishing
5825
5898
* @param click clicked or forced
5826
5899
*/
5827
- public void stopFishing (boolean click ) {
5900
+ public int stopFishing (boolean click ) {
5901
+ int itemDamage = 0 ;
5828
5902
if (this .fishing != null && click ) {
5829
- fishing .reelLine ();
5903
+ itemDamage = fishing .reelLine ();
5830
5904
} else if (this .fishing != null ) {
5831
5905
this .fishing .close ();
5832
5906
}
5833
5907
5834
5908
this .fishing = null ;
5909
+ return itemDamage ;
5835
5910
}
5836
5911
5837
5912
@ Override
@@ -6290,4 +6365,16 @@ public void showHud() {
6290
6365
*/
6291
6366
public void showHudElements (int ... elements ) {
6292
6367
}
6368
+
6369
+ public void swingArm () {
6370
+ AnimatePacket pk = new AnimatePacket ();
6371
+ pk .eid = getId ();
6372
+ pk .action = AnimatePacket .Action .SWING_ARM ;
6373
+ dataPacket (pk );
6374
+
6375
+ AnimatePacket pkBroadcast = new AnimatePacket ();
6376
+ pkBroadcast .eid = getId ();
6377
+ pkBroadcast .action = AnimatePacket .Action .SWING_ARM ;
6378
+ Server .broadcastPacket (getViewers ().values (), pkBroadcast );
6379
+ }
6293
6380
}
0 commit comments