minecraft-src/net/minecraft/world/entity/projectile/Snowball.java
2025-07-04 03:15:13 +03:00

67 lines
2 KiB
Java

package net.minecraft.world.entity.projectile;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.Blaze;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
public class Snowball extends ThrowableItemProjectile {
public Snowball(EntityType<? extends Snowball> entityType, Level level) {
super(entityType, level);
}
public Snowball(Level level, LivingEntity owner, ItemStack item) {
super(EntityType.SNOWBALL, owner, level, item);
}
public Snowball(Level level, double x, double y, double z, ItemStack item) {
super(EntityType.SNOWBALL, x, y, z, level, item);
}
@Override
protected Item getDefaultItem() {
return Items.SNOWBALL;
}
private ParticleOptions getParticle() {
ItemStack itemStack = this.getItem();
return (ParticleOptions)(itemStack.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleOption(ParticleTypes.ITEM, itemStack));
}
@Override
public void handleEntityEvent(byte id) {
if (id == 3) {
ParticleOptions particleOptions = this.getParticle();
for (int i = 0; i < 8; i++) {
this.level().addParticle(particleOptions, this.getX(), this.getY(), this.getZ(), 0.0, 0.0, 0.0);
}
}
}
@Override
protected void onHitEntity(EntityHitResult result) {
super.onHitEntity(result);
Entity entity = result.getEntity();
int i = entity instanceof Blaze ? 3 : 0;
entity.hurt(this.damageSources().thrown(this, this.getOwner()), i);
}
@Override
protected void onHit(HitResult result) {
super.onHit(result);
if (!this.level().isClientSide) {
this.level().broadcastEntityEvent(this, (byte)3);
this.discard();
}
}
}