Unicopia/src/main/java/com/minelittlepony/unicopia/mixin/MixinBlockItem.java

32 lines
1 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Mixin;
2022-09-30 12:43:07 +02:00
import com.minelittlepony.unicopia.item.toxin.ToxicHolder;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.UseAction;
import net.minecraft.world.World;
@Mixin(BlockItem.class)
abstract class MixinBlockItem extends Item implements ToxicHolder {
2022-03-26 20:34:15 +01:00
MixinBlockItem() {super(null); }
@Override
public UseAction getUseAction(ItemStack stack) {
2022-09-30 12:43:07 +02:00
return getToxic(stack).useAction().orElseGet(() -> super.getUseAction(stack));
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
2022-09-30 12:43:07 +02:00
return getToxic(player.getStackInHand(hand)).ailment().get(player)
2021-06-21 22:05:40 +02:00
.map(t -> t.use(world, player, hand))
.orElseGet(() -> super.use(world, player, hand));
}
}