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);
}
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);
}
}
}
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;
}
Aggregations