Skip to content

Commit

Permalink
Fix shields being instantly broken (#213)
Browse files Browse the repository at this point in the history
A misapplied patch caused a call to stopUsingItem(), which blanks out
the currently-using item, even if the shield didn't break.

Fixes #211
  • Loading branch information
sciwhiz12 authored Oct 31, 2023
1 parent a378a03 commit 3cc9041
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions patches/net/minecraft/world/entity/player/Player.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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_)) {
Expand All @@ -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 {
Expand All @@ -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());
}

Expand All @@ -181,39 +185,39 @@
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) {
+ net.neoforged.neoforge.event.EventHooks.onPlayerDestroyItem(this, itemstack1, p_36159_);
this.setItemInHand(p_36159_, ItemStack.EMPTY);
}

@@ -1043,6 +1068,7 @@
@@ -1043,6 +1070,7 @@
}

@Override
+ // Forge: Don't update this method to use IForgeEntity#getStepHeight() - https://github.com/MinecraftForge/MinecraftForge/issues/8922
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_;
}

+ // Forge: Don't update this method to use IForgeEntity#getStepHeight() - https://github.com/MinecraftForge/MinecraftForge/issues/9376
private boolean isAboveGround() {
return this.onGround()
|| this.fallDistance < this.maxUpStep()
@@ -1104,6 +1131,7 @@
@@ -1104,6 +1133,7 @@
}

public void attack(Entity p_36347_) {
+ if (!net.neoforged.neoforge.common.CommonHooks.onPlayerAttackTarget(this, p_36347_)) return;
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;
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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))) {
Expand All @@ -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_;
Expand All @@ -282,15 +286,15 @@
this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
}
}
@@ -1271,6 +1302,7 @@
@@ -1271,6 +1304,7 @@
}
}
}
+ this.resetAttackStrengthTicker(); // FORGE: Moved from beginning of attack() so that getAttackStrengthScale() returns an accurate value during all attack events
}
}
}
@@ -1287,7 +1319,7 @@
@@ -1287,7 +1321,7 @@
}

if (this.random.nextFloat() < f) {
Expand All @@ -299,15 +303,15 @@
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_) {
+ net.neoforged.neoforge.event.EventHooks.onPlayerWakeup(this, p_36226_, p_36227_);
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_) {
Expand All @@ -316,15 +320,15 @@
} 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) {
+ net.neoforged.neoforge.event.EventHooks.onPlayerFall(this, p_150093_, p_150093_);
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);
Expand All @@ -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();
Expand All @@ -349,7 +353,7 @@
} else {
super.playStepSound(blockpos, blockstate);
}
@@ -1638,6 +1672,10 @@
@@ -1638,6 +1674,10 @@
}

public void giveExperiencePoints(int p_36291_) {
Expand All @@ -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_) {
Expand All @@ -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_) {
Expand All @@ -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() {
Expand All @@ -393,7 +397,7 @@
return this.decorateDisplayNameComponent(mutablecomponent);
}

@@ -2026,25 +2072,25 @@
@@ -2026,25 +2074,25 @@
Predicate<ItemStack> predicate = ((ProjectileWeaponItem)p_36349_.getItem()).getSupportedHeldProjectiles();
ItemStack itemstack = ProjectileWeaponItem.getHeldProjectile(this, predicate);
if (!itemstack.isEmpty()) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3cc9041

Please sign in to comment.