All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.magistuarmory.item.MedievalBowItem Maven / Gradle / Ivy
package com.magistuarmory.item;
import dev.architectury.registry.item.ItemPropertiesRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.BowItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
public class MedievalBowItem extends BowItem implements IHasModelProperty
{
private final float pullTime;
private final float arrowSpeed;
public MedievalBowItem(Properties properties, float arrowSpeed, float pullTime)
{
super(properties);
this.arrowSpeed = arrowSpeed;
this.pullTime = pullTime;
}
@Override
public void m_5551_(ItemStack p_40667_, Level p_40668_, LivingEntity p_40669_, int p_40670_)
{
if (p_40669_ instanceof Player)
{
Player player = (Player)p_40669_;
boolean flag = player.m_150110_().f_35937_ || EnchantmentHelper.m_44843_(Enchantments.f_44952_, p_40667_) > 0;
ItemStack itemstack = player.m_6298_(p_40667_);
int i = this.m_8105_(p_40667_) - p_40670_;
if (!itemstack.m_41619_() || flag)
{
if (itemstack.m_41619_())
{
itemstack = new ItemStack(Items.f_42412_);
}
float f = getPower(i);
if (!((double)f < 0.1D))
{
boolean flag1 = player.m_150110_().f_35937_ || (itemstack.m_41720_() instanceof ArrowItem && EnchantmentHelper.m_44843_(Enchantments.f_44952_, p_40667_) > 0);
if (!p_40668_.f_46443_)
{
ArrowItem arrowitem = (ArrowItem)(itemstack.m_41720_() instanceof ArrowItem ? itemstack.m_41720_() : Items.f_42412_);
AbstractArrow abstractarrow = arrowitem.m_6394_(p_40668_, itemstack, player);
abstractarrow.m_37251_(player, player.m_146909_(), player.m_146908_(), 0.0F, f * this.arrowSpeed, 1.0F);
if (f == 1.0F)
{
abstractarrow.m_36762_(true);
}
int j = EnchantmentHelper.m_44843_(Enchantments.f_44988_, p_40667_);
if (j > 0)
{
abstractarrow.m_36781_(abstractarrow.m_36789_() + (double)j * 0.5D + 0.5D);
}
int k = EnchantmentHelper.m_44843_(Enchantments.f_44989_, p_40667_);
if (k > 0)
{
abstractarrow.m_36735_(k);
}
if (EnchantmentHelper.m_44843_(Enchantments.f_44990_, p_40667_) > 0)
{
abstractarrow.m_20254_(100);
}
p_40667_.m_41622_(1, player, (p_40665_) -> {
p_40665_.m_21190_(player.m_7655_());
});
if (flag1 || player.m_150110_().f_35937_ && (itemstack.m_150930_(Items.f_42737_) || itemstack.m_150930_(Items.f_42738_)))
{
abstractarrow.f_36705_ = AbstractArrow.Pickup.CREATIVE_ONLY;
}
p_40668_.m_7967_(abstractarrow);
}
p_40668_.m_6263_((Player)null, player.m_20185_(), player.m_20186_(), player.m_20189_(), SoundEvents.f_11687_, SoundSource.PLAYERS, 1.0F, 1.0F / (p_40668_.m_213780_().m_188501_() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !player.m_150110_().f_35937_)
{
itemstack.m_41774_(1);
if (itemstack.m_41619_())
{
player.m_150109_().m_36057_(itemstack);
}
}
player.m_36246_(Stats.f_12982_.m_12902_(this));
}
}
}
}
public float getPower(int p_185059_0_)
{
float f = (float)p_185059_0_ / this.pullTime;
f = (f * f + f * 2.0F) / 3.0F;
if (f > 1.0F)
f = 1.0F;
return f;
}
@Environment(EnvType.CLIENT)
@Override
public void registerModelProperty()
{
ItemPropertiesRegistry.register(this, new ResourceLocation("pulling"), (stack, level, entity, i) ->
entity != null && entity.m_6117_() && entity.m_21211_() == stack ? 1.0F : 0.0F);
ItemPropertiesRegistry.register(this, new ResourceLocation("pull"), (stack, level, entity, i) ->
{
if (entity == null)
return 0.0F;
else
return entity.m_21211_() != stack ? 0.0F : (float)(stack.m_41779_() - entity.m_21212_()) / 20.0F;
});
}
}