mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-23 21:40:02 -04:00
Fix ItemStack.EMPTY.getItem() rarely returning null due to threading (#2826)
* Fix ItemStack.EMPTY.getItem() rarely returning null due to threading
* Overwrite instead
(cherry picked from commit c3530bb1c6
)
This commit is contained in:
parent
d8ef6908eb
commit
693ffc0581
1 changed files with 20 additions and 0 deletions
|
@ -20,6 +20,7 @@ import java.util.function.Consumer;
|
|||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
@ -36,6 +37,7 @@ import net.minecraft.entity.attribute.EntityAttribute;
|
|||
import net.minecraft.entity.attribute.EntityAttributeModifier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemStack;
|
||||
import net.fabricmc.fabric.api.item.v1.CustomDamageHandler;
|
||||
|
@ -100,4 +102,22 @@ public abstract class ItemStackMixin implements FabricItemStack {
|
|||
public boolean hookIsSuitableFor(Item item, BlockState state) {
|
||||
return item.isSuitableFor((ItemStack) (Object) this, state);
|
||||
}
|
||||
|
||||
@Final
|
||||
@Shadow
|
||||
private Item item;
|
||||
@Shadow
|
||||
private int count;
|
||||
@Shadow
|
||||
private boolean empty;
|
||||
|
||||
/**
|
||||
* Soft-overwrite updateEmptyState to fix <a href="https://bugs.mojang.com/projects/MC/issues/MC-258939">MC-258939</a>.
|
||||
* Cannot hard-overwrite because Lithium contains a similar but insufficient inject.
|
||||
*/
|
||||
@Inject(method = "updateEmptyState", at = @At("HEAD"), cancellable = true)
|
||||
private void updateEmptyState(CallbackInfo ci) {
|
||||
this.empty = this.item == null || this.item == Items.AIR || this.count <= 0;
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue