Search in sources :

Example 1 with IItemBehaviour

use of gregtech.api.items.metaitem.stats.IItemBehaviour in project GregTech by GregTechCE.

the class MetaItem method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack itemStack = player.getHeldItem(hand);
    for (IItemBehaviour behaviour : getBehaviours(itemStack)) {
        ActionResult<ItemStack> behaviourResult = behaviour.onItemRightClick(world, player, hand);
        itemStack = behaviourResult.getResult();
        if (behaviourResult.getType() != EnumActionResult.PASS) {
            return ActionResult.newResult(behaviourResult.getType(), itemStack);
        } else if (itemStack.isEmpty()) {
            return ActionResult.newResult(EnumActionResult.PASS, ItemStack.EMPTY);
        }
    }
    IItemUseManager useManager = getUseManager(itemStack);
    if (useManager != null && useManager.canStartUsing(itemStack, player)) {
        useManager.onItemUseStart(itemStack, player);
        player.setActiveHand(hand);
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, itemStack);
}
Also used : IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) ThermalFluidHandlerItemStack(gregtech.api.capability.impl.ThermalFluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) IItemUseManager(gregtech.api.items.metaitem.stats.IItemUseManager)

Example 2 with IItemBehaviour

use of gregtech.api.items.metaitem.stats.IItemBehaviour in project GregTech by GregTechCE.

the class MetaItem method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemStack, @Nullable World worldIn, List<String> lines, ITooltipFlag tooltipFlag) {
    super.addInformation(itemStack, worldIn, lines, tooltipFlag);
    T item = getItem(itemStack);
    if (item != null) {
        String unlocalizedTooltip = "metaitem." + item.unlocalizedName + ".tooltip";
        if (I18n.hasKey(unlocalizedTooltip)) {
            lines.add(I18n.format(unlocalizedTooltip));
        }
        /*if (getCapacity(itemStack) > 0) {
                FluidStack fluid = getFluid(itemStack);
                if (fluid != null) {
                    lines.add(I18n.format("metaitem.generic.fluid_container.tooltip",
                        fluid.amount,
                        getCapacity(itemStack),
                        fluid.getLocalizedName()));
                } else lines.add(I18n.format("metaitem.generic.fluid_container.tooltip_empty"));
            }*/
        for (IItemBehaviour behaviour : getBehaviours(itemStack)) {
            behaviour.addInformation(itemStack, lines);
        }
    }
}
Also used : IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IItemBehaviour

use of gregtech.api.items.metaitem.stats.IItemBehaviour in project GregTech by GregTechCE.

the class MetaItem method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    ItemStack originalStack = stack.copy();
    for (IItemBehaviour behaviour : getBehaviours(stack)) {
        ActionResult<ItemStack> behaviourResult = behaviour.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
        stack = behaviourResult.getResult();
        if (behaviourResult.getType() != EnumActionResult.PASS) {
            if (!ItemStack.areItemStacksEqual(originalStack, stack))
                player.setHeldItem(hand, stack);
            return behaviourResult.getType();
        } else if (stack.isEmpty()) {
            player.setHeldItem(hand, ItemStack.EMPTY);
            return EnumActionResult.PASS;
        }
    }
    EnumAction useAction = getItemUseAction(stack);
    if (useAction != EnumAction.NONE) {
        player.setActiveHand(hand);
        return EnumActionResult.SUCCESS;
    }
    if (!ItemStack.areItemStacksEqual(originalStack, stack))
        player.setHeldItem(hand, stack);
    return EnumActionResult.PASS;
}
Also used : IItemBehaviour(gregtech.api.items.metaitem.stats.IItemBehaviour) ThermalFluidHandlerItemStack(gregtech.api.capability.impl.ThermalFluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack) EnumAction(net.minecraft.item.EnumAction)

Aggregations

IItemBehaviour (gregtech.api.items.metaitem.stats.IItemBehaviour)3 ThermalFluidHandlerItemStack (gregtech.api.capability.impl.ThermalFluidHandlerItemStack)2 ItemStack (net.minecraft.item.ItemStack)2 IItemUseManager (gregtech.api.items.metaitem.stats.IItemUseManager)1 EnumAction (net.minecraft.item.EnumAction)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1