Fabric Shield Lib

Fabric Shield Lib

3M Downloads

Call axe disable timer in other situations

swapmasterx opened this issue ยท 18 comments

commented

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.

commented

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.

commented

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.

commented

Yep. I just got to modify the inventory tick method I'm using to check for it

commented

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

commented

Yeah, that should be the shield item that you have trying to disable, not some class. Make sure to name variable that.

commented

What should I initialize the class variable with? It auto fills to null but I don't think that would be right

commented

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().

commented

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

commented

Try adding this line before it:
ShieldDisabledCallback.EVENT.invoker().disable(player, player.getActiveHand(), activeItemStack);

commented

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.

commented

@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());
}

commented

Is there anything else I can do here?

commented

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.

commented

Alrighty. It at least does get called but doesn't properly cancel the input is my guess given the brief fov shift.

commented

Still not having success over here fixing the bug on my end

commented

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.

commented

@swapmasterx do you still need help with this?

commented

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.