Netherite Plus Mod

Netherite Plus Mod

1M Downloads

[1.19.1] [Quillt] Missing zoom on Netherite Bow

kwpugh opened this issue ยท 2 comments

commented

While pulling the bow, it does not provide the zoom effect that vanilla bows provide;

2022-07-31_17 51 04

commented

Dynamic FOV changes are provided by conditionals in the getFoVMultiplier() method in net.minecraft.client.network.AbstractClientPlayerEntity. This checks to see if the player is flying, has a modified movement speed, is using a spyglass, or is using specifically Items.BOW. Overwriting the method (heavy handed, I know, but I'm new to modding and mixins) with one that checked:
if (itemStack.isOf(Items.BOW) || itemStack.isOf(ModItems.NETHERITE_BOW)) {...
worked in my case.

@Mixin(AbstractClientPlayerEntity.class)`
public abstract class ModAbstractClientPlayerEntity extends PlayerEntity{

public ModAbstractClientPlayerEntity(World world, BlockPos pos, float yaw, GameProfile gameProfile, 
        @Nullable PlayerPublicKey publicKey) {
    super(world, pos, yaw, gameProfile, publicKey);
}

@Overwrite
public float getFovMultiplier() {
    float f = 1.0f;
    if (this.getAbilities().flying) {
        f *= 1.1f;
    }
    if (this.getAbilities().getWalkSpeed() == 0.0f || 
            Float.isNaN(f *= ((float)this.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED) 
            / this.getAbilities().getWalkSpeed() + 1.0f) / 2.0f) || Float.isInfinite(f)) {
        f = 1.0f;
    }
    ItemStack itemStack = this.getActiveItem();
    if (this.isUsingItem()) {
        if (itemStack.isOf(Items.BOW) || itemStack.isOf(ModItems.NETHERITE_BOW)) {
            int i = this.getItemUseTime();
            float g = (float)i / 20.0f;
            g = g > 1.0f ? 1.0f : (g *= g);
            f *= 1.0f - g * 0.15f;
        } else if (MinecraftClient.getInstance().options.getPerspective().isFirstPerson() && this.isUsingSpyglass()) {
            return 0.1f;
        }
    }
    return MathHelper.lerp(MinecraftClient.getInstance().options.getFovEffectScale().getValue().floatValue(), 
        1.0f, f);
}

}

Edit: Implementation of the above using a redirect, rather than an overwrite -

@Redirect(
    method = "getFovMultiplier()F", 
    at = @At(value = "INVOKE", 
    target =  "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z")
)
private boolean injected(ItemStack itemStack, Item item){
    return (itemStack.isOf(item) || itemStack.isOf(ModItems.NETHERITE_BOW));
}
commented

Closing as the fix will come in QuiltMC/quilt-standard-libraries#340 and for 1.20