32 lines
1 KiB
Java
32 lines
1 KiB
Java
package net.minecraft.client.renderer.item.properties.numeric;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
import net.fabricmc.api.EnvType;
|
|
import net.fabricmc.api.Environment;
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.item.CrossbowItem;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
public class CrossbowPull implements RangeSelectItemModelProperty {
|
|
public static final MapCodec<CrossbowPull> MAP_CODEC = MapCodec.unit(new CrossbowPull());
|
|
|
|
@Override
|
|
public float get(ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int seed) {
|
|
if (entity == null) {
|
|
return 0.0F;
|
|
} else if (CrossbowItem.isCharged(stack)) {
|
|
return 0.0F;
|
|
} else {
|
|
int i = CrossbowItem.getChargeDuration(stack, entity);
|
|
return (float)UseDuration.useDuration(stack, entity) / i;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public MapCodec<CrossbowPull> type() {
|
|
return MAP_CODEC;
|
|
}
|
|
}
|