Dispenser Behavior Support
Link to dispenser-behavior-support
CraftTweaker allows you to add or remove dispenser behaviors.
Removal
Link to removal
Use IItemDefinition#removeDispenserBehavior
method to remove dispenser behavior of the specific item.
ZenScript Copy// Dispenser can no longer shoot arrows
<minecraft:arrow>.definition.removeDispenserBehavior();
Suma
Link to suma
Use the IItemDefinition#addDispenserBehavior
method to add dispenser behavior for the specific item.
itemDef.addDispenserBehavior(IDispenserBehavior behavior, @Optional IDispenserSoundFunction soundFunction)
IDispenserBehavior
Link to idispenserbehavior
The IDispenserBehavior function defines how a Dispenser dispenses the item. It has two parameters:
source
: An IBlockSource containing some information of the dispenser.item
: The IItemStack to be dispensed.
The function must return an IItemStack as the remaining item after dispensed.
IDispenserSoundFunction
Link to idispensersoundfunction
The IDispenserSoundFunction defines what sound the dispenser should play. It has an IBlockSource parameter. The function must return a DispenserSound.
Ejemplo
Link to ejemplo
ZenScript Copyimport crafttweaker.dispenser.DispenserSound;
<minecraft:clay_ball>.definition.addDispenserBehavior(function(source, item) {
print("balance.");
item.mutable().shrink(1);
return item;
}, function(source) {
return DispenserSound.launch();
});
Shooting Projectile Behavior
Link to shooting-projectile-behavior
ZenScript Copy// itemDef.addShootingProjectileDispenserBehavior(IEntityDefinition projectile, @Optional float inaccuracy, @Optional float velocity);
<minecraft:apple>.definition.addShootingProjectileDispenserBehavior(<entity:minecraft:egg>);
// NOTE: the default value of inaccuracy is 6.0 and velocity is 1.1