Fixed horseshoes shot from dispensers not using their correct speed for the item fired

This commit is contained in:
Sollace 2024-11-01 14:02:45 +00:00
parent 653fc0bcf7
commit 1920233090
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -16,6 +16,7 @@ import net.minecraft.component.type.AttributeModifierSlot;
import net.minecraft.component.type.AttributeModifiersComponent; import net.minecraft.component.type.AttributeModifiersComponent;
import net.minecraft.entity.attribute.EntityAttributeModifier; import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.tooltip.TooltipType; import net.minecraft.item.tooltip.TooltipType;
@ -92,6 +93,20 @@ public class HorseShoeItem extends HeavyProjectileItem {
return projectile; return projectile;
} }
@Override
public void initializeProjectile(ProjectileEntity entity, double x, double y, double z, float power, float uncertainty) {
float degradation = 0;
if (entity instanceof PhysicsBodyProjectileEntity p) {
ItemStack stack = p.getStack();
degradation = (stack.getDamage() / (float)stack.getMaxDamage());
}
float speed = Math.max(0.2F, ((baseProjectileSpeed + 0.1F) / 1.5F) * (1 - (0.6F * degradation)));
float inaccuracy = projectileInnacuracy + degradation * 30;
entity.setVelocity(x, y, z, speed, inaccuracy);
}
@Override @Override
public SoundEvent getThrowSound(ItemStack stack) { public SoundEvent getThrowSound(ItemStack stack) {
return USounds.Vanilla.ITEM_TRIDENT_THROW.value(); return USounds.Vanilla.ITEM_TRIDENT_THROW.value();