package com.thebrokenrail.scriptcraft.api.item; import com.thebrokenrail.scriptcraft.core.ValueUtil; import com.thebrokenrail.scriptcraft.core.quickjs.QuickJSManager; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; public class CustomItem extends Item { private final Identifier id; public CustomItem(Settings settings, Identifier id) { super(settings); this.id = id; } @Override public TypedActionResult use(World world, PlayerEntity user, Hand hand) { ItemStack stack = user.getStackInHand(hand); ActionResult result = ValueUtil.getEnumValue(ActionResult.class, (String) QuickJSManager.bridge("CustomItem.onUse", id.toString(), world, user, hand.name()), ActionResult.PASS); return new TypedActionResult<>(result, stack); } @Override public ActionResult useOnBlock(ItemUsageContext context) { return ValueUtil.getEnumValue(ActionResult.class, (String) QuickJSManager.bridge("CustomItem.onUseOnBlock", id.toString(), context.getWorld(), (double) context.getBlockPos().getX(), (double) context.getBlockPos().getY(), (double) context.getBlockPos().getZ(), context.getSide().name(), context.getPlayer(), context.getHand().name()), ActionResult.PASS); } @Override public boolean useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { return ValueUtil.toBoolean(QuickJSManager.bridge("CustomItem.onUseOnEntity", id.toString(), user, entity, hand.name()), false); } }