-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the holding LivingEntity instance for getPreferredEquipmentSlot i…
…n getEquipmentSlot (#169) Fixes a crash whenever that method is called, as Item cannot be cast to LivingEntity Signed-off-by: unilock <[email protected]>
- Loading branch information
Showing
5 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/impl/item/ItemStackExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.fabricmc.fabric.impl.item; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface ItemStackExtensions { | ||
@Nullable LivingEntity fabric_getLivingEntity(); | ||
void fabric_setLivingEntity(LivingEntity livingEntity); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
fabric-item-api-v1/src/main/java/net/fabricmc/fabric/mixin/item/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.fabricmc.fabric.mixin.item; | ||
|
||
import net.fabricmc.fabric.impl.item.ItemStackExtensions; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(LivingEntity.class) | ||
abstract class LivingEntityMixin { | ||
@Inject(method = "getEquipmentSlotForItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getEquipmentSlot()Lnet/minecraft/world/entity/EquipmentSlot;")) | ||
private void storeLivingEntity(ItemStack arg, CallbackInfoReturnable<EquipmentSlot> cir) { | ||
((ItemStackExtensions) (Object) arg).fabric_setLivingEntity((LivingEntity) (Object) this); | ||
} | ||
|
||
@Inject(method = "getEquipmentSlotForItem", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/item/ItemStack;getEquipmentSlot()Lnet/minecraft/world/entity/EquipmentSlot;")) | ||
private void resetLivingEntity(ItemStack arg, CallbackInfoReturnable<EquipmentSlot> cir) { | ||
((ItemStackExtensions) (Object) arg).fabric_setLivingEntity(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters