Integrated Dynamics - On the Dynamics of Integration

Object methods

To counter the verbosity of global functions, you can write code more compactly using object methods.

Object value types such as Blocks, Items, Fluids, ... will have methods attached to them when used in JavaScript.

Object methods are just plain functions, but their first argument is tied to the object value.

For example, the global function itemstackStackable takes a single Item argument and outputs a Boolean. This function is available as a method on Item values via the name stackable, which takes zero arguments.

Global functions that accept two or more arguments will be available as method on object values, with all arguments shifted by one. For example, the global function itemstackStrength accepts an Item and a Block argument, but is also available as method on Items with a single Block argument.

function filterItemMethods(item) {
  return item.isStackable() && item.size() >= 16;
}
function filterItemMethods2(item, block) {
  return item.strength(block) > 10;
}
function filterItemMethods3(item) {
  return item.nbt().Damage === 0;
}