Skip to content

ZenUtilsPlayer

youyihj edited this page Jul 29, 2023 · 7 revisions

ZenUtilsPlayer

ZenUtilsPlayer is an expansion of IPlayer (crafttweaker.player.IPlayer).

Calling the methods

As this is a ZenExpansion, you can simply call the methods on any IPlayer object, or any of it's subtypes.

ZenMethods

// Replace item at the given index within player's inventory
// will return a bool that states if the replacement is successful
// playerObj.replaceItemInInventory(int inventorySlot, IItemStack itemStack);
playerObj.replaceItemInInventory(20, <item:minecraft:iron_ingot> * 4);

@since 1.12.3
// gets a statistic field of the player
// returns an int
// playerObj.readStat(PlayerStat stat);
playerObj.readStat(PlayerStat.getBasicStat("stat.jump"));
// adds a value to a statistic field
// the amount parameter can be omitted, default is 1
// playerObj.addStat(PlayerStat stat, int amount)
playerObj.addStat(PlayerStat.getBasicStat("stat.jump"), 4);
// sets a statistic field to zero
// playerObj.takeStat(PlayerStat stat)
playerObj.takeStat(PlayerStat.getBasicStat("stat.jump"));

Player Interaction Simulation

@since 1.14.3

ZenUtils allows to simulate a player interaction (right or left click). These methods are supposed to called only on server side.

simulateRightClickItem

Simulates a player right clicking an item but isn't targeting at a block or entity.

Returns a string represents the result of this interaction.

Probably return value: SUCCESS PASS FAIL

player.simulateRightClickItem(item, hand);

Parameter Type Description Default value
item IItemStack The item that the player used
hand IEntityEquipmentSlot The hand that the player used. Only mainHand and offHand is allowed mainHand

simulateRightClickBlock

Simulates a player right clicking a block with an item in hand.

Returns a string represents the result of this interaction.

Probably return value: SUCCESS PASS FAIL

player.simulateRightClickBlock(item, hand, pos, side, hitX, hitY, hitZ);

Parameter Type Description Default value
item IItemStack The item that the player used
hand IEntityEquipmentSlot The hand that the player used. Only mainHand and offHand is allowed mainHand
pos IBlockPos The position of the block to be interacted Determined by the player's eye direction
side IFacing The side of the block to be interacted Determined by the player's eye direction
hitX float The relative X coordinate of the player click point, ranging from 0 to 1 Determined by the player's eye direction
hitY float The relative Y coordinate of the point the player clicked, ranging from 0 to 1 Determined by the player's eye direction
hitZ float The relative Z coordinate of the player click point, ranging from 0 to 1 Determined by the player's eye direction

simulateRightClickEntity

Simulates a player right clicking an entity with a item in hand.

Returns a string represents the result of this interaction.

Probably return value: SUCCESS PASS FAIL

player.simulateRightClickEntity(entity, item, hand)

Parameter Type Description Default value
entity IEntity The entity to be interacted
item IItemStack The item that the player used the item the player held in the given hand
hand IEntityEquipmentSlot The hand that the player used. Only mainHand and offHand is allowed mainHand

simulateLeftClickBlock

Simulates a player left clicking a block by main hand. Returns nothing.

player.simulateRightClickEntity(item, pos, side)

Parameter Type Description Default value
item IItemStack The item that the player used The item the player held in main hand
pos IBlockPos The position of the block to be interacted Determined by the player's eye direction
side IFacing The side of the block to be interacted Determined by the player's eye direction

simulateUseItemFinish

Simulates a player finishing using an item. (e.g. finishes eating)

Returns the result item, such as milk bucket to empty bucket.

player.simulateUseItemFinish(item, hand)

Parameter Type Description Default value
item IItemStack The item that the player used
hand IEntityEquipmentSlot The hand that the player used. Only mainHand and offHand is allowed player active hand
Clone this wiki locally