From 3cc9041bc1d5b6c636133136329db7da90eeac6c Mon Sep 17 00:00:00 2001 From: sciwhiz12 Date: Tue, 31 Oct 2023 22:19:27 +0800 Subject: [PATCH] Fix shields being instantly broken (#213) A misapplied patch caused a call to stopUsingItem(), which blanks out the currently-using item, even if the shield didn't break. Fixes #211 --- .../world/entity/player/Player.java.patch | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/patches/net/minecraft/world/entity/player/Player.java.patch b/patches/net/minecraft/world/entity/player/Player.java.patch index 034f68c58d..f77be25295 100644 --- a/patches/net/minecraft/world/entity/player/Player.java.patch +++ b/patches/net/minecraft/world/entity/player/Player.java.patch @@ -139,16 +139,20 @@ if (!this.level().isClientSide) { this.awardStat(Stats.ITEM_USED.get(this.useItem.getItem())); } -@@ -906,6 +920,8 @@ +@@ -905,7 +919,11 @@ + if (p_36383_ >= 3.0F) { int i = 1 + Mth.floor(p_36383_); InteractionHand interactionhand = this.getUsedItemHand(); - this.useItem.hurtAndBreak(i, this, p_219739_ -> p_219739_.broadcastBreakEvent(interactionhand)); +- this.useItem.hurtAndBreak(i, this, p_219739_ -> p_219739_.broadcastBreakEvent(interactionhand)); ++ this.useItem.hurtAndBreak(i, this, p_219739_ -> { ++ p_219739_.broadcastBreakEvent(interactionhand); + net.neoforged.neoforge.event.EventHooks.onPlayerDestroyItem(this, this.useItem, interactionhand); -+ stopUsingItem(); // Forge: fix MC-168573 ++ stopUsingItem(); // Neo: Fix MC-168573 ("After breaking a shield, the player's off-hand can't finish using some items") ++ }); if (this.useItem.isEmpty()) { if (interactionhand == InteractionHand.MAIN_HAND) { this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY); -@@ -923,10 +939,13 @@ +@@ -923,10 +941,13 @@ @Override protected void actuallyHurt(DamageSource p_36312_, float p_36313_) { if (!this.isInvulnerableTo(p_36312_)) { @@ -162,7 +166,7 @@ float f = p_36313_ - f1; if (f > 0.0F && f < 3.4028235E37F) { this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f * 10.0F)); -@@ -990,6 +1009,8 @@ +@@ -990,6 +1011,8 @@ return InteractionResult.PASS; } else { @@ -171,7 +175,7 @@ ItemStack itemstack = this.getItemInHand(p_36159_); ItemStack itemstack1 = itemstack.copy(); InteractionResult interactionresult = p_36158_.interact(this, p_36159_); -@@ -998,6 +1019,9 @@ +@@ -998,6 +1021,9 @@ itemstack.setCount(itemstack1.getCount()); } @@ -181,7 +185,7 @@ return interactionresult; } else { if (!itemstack.isEmpty() && p_36158_ instanceof LivingEntity) { -@@ -1009,6 +1033,7 @@ +@@ -1009,6 +1035,7 @@ if (interactionresult1.consumesAction()) { this.level().gameEvent(GameEvent.ENTITY_INTERACT, p_36158_.position(), GameEvent.Context.of(this)); if (itemstack.isEmpty() && !this.abilities.instabuild) { @@ -189,7 +193,7 @@ this.setItemInHand(p_36159_, ItemStack.EMPTY); } -@@ -1043,6 +1068,7 @@ +@@ -1043,6 +1070,7 @@ } @Override @@ -197,7 +201,7 @@ protected Vec3 maybeBackOffFromEdge(Vec3 p_36201_, MoverType p_36202_) { if (!this.abilities.flying && p_36201_.y <= 0.0 -@@ -1097,6 +1123,7 @@ +@@ -1097,6 +1125,7 @@ return p_36201_; } @@ -205,7 +209,7 @@ private boolean isAboveGround() { return this.onGround() || this.fallDistance < this.maxUpStep() -@@ -1104,6 +1131,7 @@ +@@ -1104,6 +1133,7 @@ } public void attack(Entity p_36347_) { @@ -213,7 +217,7 @@ if (p_36347_.isAttackable()) { if (!p_36347_.skipAttackInteraction(this)) { float f = (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE); -@@ -1117,11 +1145,10 @@ +@@ -1117,11 +1147,10 @@ float f2 = this.getAttackStrengthScale(0.5F); f *= 0.2F + f2 * f2 * 0.8F; f1 *= f2; @@ -226,7 +230,7 @@ i += EnchantmentHelper.getKnockbackBonus(this); if (this.isSprinting() && flag) { this.level().playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); -@@ -1138,8 +1165,10 @@ +@@ -1138,8 +1167,10 @@ && !this.isPassenger() && p_36347_ instanceof LivingEntity; flag2 = flag2 && !this.isSprinting(); @@ -238,7 +242,7 @@ } f += f1; -@@ -1147,9 +1176,7 @@ +@@ -1147,9 +1178,7 @@ double d0 = (double)(this.walkDist - this.walkDistO); if (flag && !flag2 && !flag1 && this.onGround() && d0 < (double)this.getSpeed()) { ItemStack itemstack = this.getItemInHand(InteractionHand.MAIN_HAND); @@ -249,7 +253,7 @@ } float f4 = 0.0F; -@@ -1190,11 +1217,13 @@ +@@ -1190,11 +1219,13 @@ float f3 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(this) * f; for(LivingEntity livingentity : this.level().getEntitiesOfClass(LivingEntity.class, p_36347_.getBoundingBox().inflate(1.0, 0.25, 1.0))) { @@ -264,7 +268,7 @@ livingentity.knockback( 0.4F, (double)Mth.sin(this.getYRot() * (float) (Math.PI / 180.0)), (double)(-Mth.cos(this.getYRot() * (float) (Math.PI / 180.0))) ); -@@ -1238,13 +1267,15 @@ +@@ -1238,13 +1269,15 @@ EnchantmentHelper.doPostDamageEffects(this, p_36347_); ItemStack itemstack1 = this.getMainHandItem(); Entity entity = p_36347_; @@ -282,7 +286,7 @@ this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); } } -@@ -1271,6 +1302,7 @@ +@@ -1271,6 +1304,7 @@ } } } @@ -290,7 +294,7 @@ } } } -@@ -1287,7 +1319,7 @@ +@@ -1287,7 +1321,7 @@ } if (this.random.nextFloat() < f) { @@ -299,7 +303,7 @@ this.stopUsingItem(); this.level().broadcastEntityEvent(this, (byte)30); } -@@ -1349,6 +1381,7 @@ +@@ -1349,6 +1383,7 @@ } public void stopSleepInBed(boolean p_36226_, boolean p_36227_) { @@ -307,7 +311,7 @@ super.stopSleeping(); if (this.level() instanceof ServerLevel && p_36227_) { ((ServerLevel)this.level()).updateSleepingPlayerList(); -@@ -1375,7 +1408,7 @@ +@@ -1375,7 +1410,7 @@ } else if (block instanceof BedBlock && BedBlock.canSetSpawn(p_36131_)) { return BedBlock.findStandUpPosition(EntityType.PLAYER, p_36131_, p_36132_, blockstate.getValue(BedBlock.FACING), p_36133_); } else if (!p_36134_) { @@ -316,7 +320,7 @@ } else { boolean flag = block.isPossibleToRespawnInThis(blockstate); BlockState blockstate1 = p_36131_.getBlockState(p_36132_.above()); -@@ -1561,6 +1594,7 @@ +@@ -1561,6 +1596,7 @@ @Override public boolean causeFallDamage(float p_150093_, float p_150094_, DamageSource p_150095_) { if (this.abilities.mayfly) { @@ -324,7 +328,7 @@ return false; } else { if (p_150093_ >= 2.0F) { -@@ -1574,7 +1608,7 @@ +@@ -1574,7 +1610,7 @@ public boolean tryToStartFallFlying() { if (!this.onGround() && !this.isFallFlying() && !this.isInWater() && !this.hasEffect(MobEffects.LEVITATION)) { ItemStack itemstack = this.getItemBySlot(EquipmentSlot.CHEST); @@ -333,7 +337,7 @@ this.startFallFlying(); return true; } -@@ -1603,13 +1637,13 @@ +@@ -1603,13 +1639,13 @@ protected void playStepSound(BlockPos p_282121_, BlockState p_282194_) { if (this.isInWater()) { this.waterSwimSound(); @@ -349,7 +353,7 @@ } else { super.playStepSound(blockpos, blockstate); } -@@ -1638,6 +1672,10 @@ +@@ -1638,6 +1674,10 @@ } public void giveExperiencePoints(int p_36291_) { @@ -360,7 +364,7 @@ this.increaseScore(p_36291_); this.experienceProgress += (float)p_36291_ / (float)this.getXpNeededForNextLevel(); this.totalExperience = Mth.clamp(this.totalExperience + p_36291_, 0, Integer.MAX_VALUE); -@@ -1665,7 +1703,7 @@ +@@ -1665,7 +1705,7 @@ } public void onEnchantmentPerformed(ItemStack p_36172_, int p_36173_) { @@ -369,7 +373,7 @@ if (this.experienceLevel < 0) { this.experienceLevel = 0; this.experienceProgress = 0.0F; -@@ -1676,6 +1714,10 @@ +@@ -1676,6 +1716,10 @@ } public void giveExperienceLevels(int p_36276_) { @@ -380,7 +384,7 @@ this.experienceLevel += p_36276_; if (this.experienceLevel < 0) { this.experienceLevel = 0; -@@ -1879,7 +1921,11 @@ +@@ -1879,7 +1923,11 @@ @Override public Component getDisplayName() { @@ -393,7 +397,7 @@ return this.decorateDisplayNameComponent(mutablecomponent); } -@@ -2026,25 +2072,25 @@ +@@ -2026,25 +2074,25 @@ Predicate predicate = ((ProjectileWeaponItem)p_36349_.getItem()).getSupportedHeldProjectiles(); ItemStack itemstack = ProjectileWeaponItem.getHeldProjectile(this, predicate); if (!itemstack.isEmpty()) { @@ -423,7 +427,7 @@ this.awardStat(Stats.ITEM_USED.get(p_36186_.getItem())); p_36185_.playSound( null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_BURP, SoundSource.PLAYERS, 0.5F, p_36185_.random.nextFloat() * 0.1F + 0.9F -@@ -2160,5 +2206,63 @@ +@@ -2160,5 +2208,63 @@ public Component getMessage() { return this.message; }