IItemUse Function
Link to iitemuse-function
An itemUseFunction is called whenever the associated item is used on a block.
导入相关包
Link to 导入相关包
It might be required for you to import the package if you encounter any issues, so better be safe than sorry and add the import.
import mods.contenttweaker.IItemUse;
Parameters
Link to parameters
The IItemUse function is a function with the following parameters (In this order):
- ICTPlayer player → The player doing the right-click
- IWorld world → The world the player is in
- IBlockPos pos → The Position of the block the item is used on
- Hand hand → The used Hand (main or off)
- Facing facing → The side of the block the item is used on
- Position3f blockHit → The block's relative X,Y and Z coordinate → All three are between 0 and 1
The function needs to return an ActionResult object.
ZenScript Copy#loader contenttweaker
import mods.contenttweaker.VanillaFactory;
import mods.contenttweaker.ActionResult;
var item = VanillaFactory.createItem("fake_flint");
item.maxStackSize = 1;
item.maxDamage = 50;
item.onItemUse = function(player, world, pos, hand, facing, blockHit) {
var firePos = pos.getOffset(facing, 1);
if (world.getBlockState(firePos).isReplaceable(world, firePos)) {
world.setBlockState(<block:minecraft:fire>, firePos);
player.getHeldItem(hand).damage(1, player);
return ActionResult.success();
}
return ActionResult.pass();
};
item.register();