IItemInteractionForEntity
Link to iiteminteractionforentity
The IItemInteractionForEntity function can be added to an Item and will be triggered when a player right clicks on an entity with the item.
导入相关包
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.IItemInteractionForEntity;
Parameters
Link to parameters
The IItemInteractionForEntity function is a function with the following parameters:
- IMutableItemStack itemStack → The item that was used
- ICTPlayer player → The player using the item
- IEntityLivingBase target → The entity the item was used on
- String hand → Either "OFF_HAND" or "MAIN_HAND"
The function needs to return either true
or false
ZenScript Copy#loader contenttweaker
import mods.contenttweaker.VanillaFactory;
import mods.contenttweaker.Item;
import mods.contenttweaker.IItemInteractionForEntity;
import crafttweaker.entity.IEntityLivingBase;
var sheep_remover = VanillaFactory.createItem("sheep_remover");
sheep_remover.itemInteractionForEntity = function(stack, player, target, hand) {
if target.definition.id == "minecraft:sheep" {
target.removeFromWorld();
stack.shrink(1);
return true;
}
return false;
};
sheep_remover.register();