com.magistuarmory.item.MedievalBowItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.20.2-epic-knights-common Show documentation
Show all versions of 1.20.2-epic-knights-common Show documentation
mod that adds medieval stuff to the game
package com.magistuarmory.item;
import dev.architectury.registry.item.ItemPropertiesRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_1309;
import net.minecraft.class_1657;
import net.minecraft.class_1665;
import net.minecraft.class_1744;
import net.minecraft.class_1753;
import net.minecraft.class_1799;
import net.minecraft.class_1802;
import net.minecraft.class_1890;
import net.minecraft.class_1893;
import net.minecraft.class_1937;
import net.minecraft.class_2960;
import net.minecraft.class_3417;
import net.minecraft.class_3419;
import net.minecraft.class_3468;
public class MedievalBowItem extends class_1753 implements IHasModelProperty
{
private final float pullTime;
private final float arrowSpeed;
public MedievalBowItem(class_1793 properties, float arrowSpeed, float pullTime)
{
super(properties);
this.arrowSpeed = arrowSpeed;
this.pullTime = pullTime;
}
@Override
public void method_7840(class_1799 p_40667_, class_1937 p_40668_, class_1309 p_40669_, int p_40670_)
{
if (p_40669_ instanceof class_1657)
{
class_1657 player = (class_1657)p_40669_;
boolean flag = player.method_31549().field_7477 || class_1890.method_8225(class_1893.field_9125, p_40667_) > 0;
class_1799 itemstack = player.method_18808(p_40667_);
int i = this.method_7881(p_40667_) - p_40670_;
if (!itemstack.method_7960() || flag)
{
if (itemstack.method_7960())
{
itemstack = new class_1799(class_1802.field_8107);
}
float f = getPower(i);
if (!((double)f < 0.1D))
{
boolean flag1 = player.method_31549().field_7477 || (itemstack.method_7909() instanceof class_1744 && class_1890.method_8225(class_1893.field_9125, p_40667_) > 0);
if (!p_40668_.field_9236)
{
class_1744 arrowitem = (class_1744)(itemstack.method_7909() instanceof class_1744 ? itemstack.method_7909() : class_1802.field_8107);
class_1665 abstractarrow = arrowitem.method_7702(p_40668_, itemstack, player);
abstractarrow.method_24919(player, player.method_36455(), player.method_36454(), 0.0F, f * this.arrowSpeed, 1.0F);
if (f == 1.0F)
{
abstractarrow.method_7439(true);
}
int j = class_1890.method_8225(class_1893.field_9103, p_40667_);
if (j > 0)
{
abstractarrow.method_7438(abstractarrow.method_7448() + (double)j * 0.5D + 0.5D);
}
int k = class_1890.method_8225(class_1893.field_9116, p_40667_);
if (k > 0)
{
abstractarrow.method_7449(k);
}
if (class_1890.method_8225(class_1893.field_9126, p_40667_) > 0)
{
abstractarrow.method_5639(100);
}
p_40667_.method_7956(1, player, (p_40665_) -> {
p_40665_.method_20236(player.method_6058());
});
if (flag1 || player.method_31549().field_7477 && (itemstack.method_31574(class_1802.field_8236) || itemstack.method_31574(class_1802.field_8087)))
{
abstractarrow.field_7572 = class_1665.class_1666.field_7594;
}
p_40668_.method_8649(abstractarrow);
}
p_40668_.method_43128((class_1657)null, player.method_23317(), player.method_23318(), player.method_23321(), class_3417.field_14600, class_3419.field_15248, 1.0F, 1.0F / (p_40668_.method_8409().method_43057() * 0.4F + 1.2F) + f * 0.5F);
if (!flag1 && !player.method_31549().field_7477)
{
itemstack.method_7934(1);
if (itemstack.method_7960())
{
player.method_31548().method_7378(itemstack);
}
}
player.method_7259(class_3468.field_15372.method_14956(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 class_2960("pulling"), (stack, level, entity, i) ->
entity != null && entity.method_6115() && entity.method_6030() == stack ? 1.0F : 0.0F);
ItemPropertiesRegistry.register(this, new class_2960("pull"), (stack, level, entity, i) ->
{
if (entity == null)
return 0.0F;
else
return entity.method_6030() != stack ? 0.0F : (float)(stack.method_7935() - entity.method_6014()) / 20.0F;
});
}
}