StellarWind22 / Fabric-Shield-Lib

Library for easily adding new shields, shield enchantments, and enabling you to enchant shields in general without worry of conflictions.
https://www.curseforge.com/minecraft/mc-mods/fabric-shield-lib
GNU Lesser General Public License v2.1
40 stars 18 forks source link

Call axe disable timer in other situations #150

Open swapmasterx opened 1 year ago

swapmasterx commented 1 year ago

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.

CringeStar commented 1 year ago

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.

swapmasterx commented 1 year ago

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

swapmasterx commented 1 year ago

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

CringeStar commented 1 year ago

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

swapmasterx commented 1 year ago

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

CringeStar commented 1 year ago

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

swapmasterx commented 1 year ago

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

CringeStar commented 1 year ago

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

swapmasterx commented 1 year ago

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.

swapmasterx commented 1 year ago

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

swapmasterx commented 1 year ago

Is there anything else I can do here?

CringeStar commented 1 year ago

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.

swapmasterx commented 1 year ago

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

swapmasterx commented 1 year ago

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

CringeStar commented 1 year ago

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.

CringeStar commented 1 year ago

@swapmasterx do you still need help with this?

swapmasterx commented 12 months ago

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.

CringeStar commented 6 months ago

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.