Scarpet suggestion: Allow use of Scarpet API to set cooldown timers on items for players
James103 opened this issue ยท 1 comments
Currently, there is no way to interact with the player.getItemCooldownManager().set(item, ticks)
method via the Scarpet API. It would be great if there was, as that would allow Scarpet scripts to set cooldowns on items when they are used for custom abilities in similar ways that other Fabric mods such as Identity (example use) do it.
put("item_cooldown", (e, v) ->
{
if (e instanceof ItemEntity)
{
if(!(v instanceof ListValue))
throw new InternalExpressionException("'item_cooldown' expected a list as a second argument");
ListValue lv = ((ListValue) v);
Value playersVal = lv.getItems().get(0);
int duration = ((NumericValue)lv.getItems().get(1)).getInt();
if(playersVal instanceof ListValue){
for(Value playerVal:((ListValue) playersVal).getItems()){
PlayerEntity player = EntityValue.getPlayerByValue(e.getServer(),playerVal);
player.getItemCooldownManager().set(((ItemEntity)e).getStack().getItem(),duration);
}
} else {//if its just 1 player
PlayerEntity player = EntityValue.getPlayerByValue(e.getServer(),playersVal);
player.getItemCooldownManager().set(((ItemEntity)e).getStack().getItem(),duration);
}
}
});
This is solution, allowing for: modify(item_entity,'cooldown',[player/player_list, duration])
cos its a per-player thing but we want cooldown to be per-item. too lazy to pr rn tho.