
Call axe disable timer in other situations
swapmasterx opened this issue ยท 18 comments
How would I call the activation of the disable timer in cases outside just an axe. For example, calling it when the shield reaches a certain durability threshold.
So calling the disable event starts the cool down but does not disable active shields? I'll have to look into how this event is structured.
the code to disable the shield is player.getItemCooldownManager().set((Item) shield, shield.getCoolDownTicks());
where player is the PlayerEntity and shield is the ActiveItem if it is a shield. I would assume you jusr run that when the durability is low.
Last thing, the two shield methods after item don't know where to go and I'm not finding the right symbol pathing for it
Yeah, that should be the shield item that you have trying to disable, not some class. Make sure to name variable that.
What should I initialize the class variable with? It auto fills to null but I don't think that would be right
It could either be Item, ActiveItem, ShieldItem, FabricShieldItem, or FabricBannerShieldItem, depending on the context. If you are trying to get the shield that the player has equipped, set it to equal player.getActiveItem().
So it works but it doesn't force the shield off being active. I can keep holding rightclick to keep the shield up even if it gets put on cooldown. Letting go the cooldown blocks it from being used as intended but it doesn't seem calling it this way forces you to stop using it
Try adding this line before it:
ShieldDisabledCallback.EVENT.invoker().disable(player, player.getActiveHand(), activeItemStack);
There's a brief fov change now when the cooldown is triggered but I can still keep the shield up. I'll post the block of code that calls it on a follow up post to see if one of the parts is messing with intended function.
@OverRide
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected) {
if (entity instanceof PlayerEntity player && Math.max(0, stack.getMaxDamage() - stack.getDamage())
<= 5 && !player.getItemCooldownManager().isCoolingDown(this)) {
FabricShieldItem shield = this;
ShieldDisabledCallback.EVENT.invoker().disable(player, player.getActiveHand(), stack);
player.getItemCooldownManager().set((Item) shield, shield.getCoolDownTicks());
}
That code looks right to me, so I don't know what else to change. I will have tk test it myself when I have the time.
Alrighty. It at least does get called but doesn't properly cancel the input is my guess given the brief fov shift.
hey im coming back to this issue as I'm trying to update the lib, can you explain the issue/bug again, our previous comments don't ring any bells.
@swapmasterx do you still need help with this?
Sorry, been taking a large break from modding. Essentially the bug is that even when the cooldown is called via another means if you hold right click you can keep the shield up even when the item is visible on cooldown. Letting go of rightclick while on cooldown and you can't raise the shield again until the cooldown expires as expected.