| 1 | package net.minecraft.world.entity.projectile.throwableitemprojectile;
|
| 2 |
|
| 3 | import net.minecraft.core.particles.ItemParticleOption;
|
| 4 | import net.minecraft.core.particles.ParticleOptions;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.world.entity.Entity;
|
| 7 | import net.minecraft.world.entity.EntityEvent;
|
| 8 | import net.minecraft.world.entity.EntityType;
|
| 9 | import net.minecraft.world.entity.EntityTypes;
|
| 10 | import net.minecraft.world.entity.LivingEntity;
|
| 11 | import net.minecraft.world.entity.monster.Blaze;
|
| 12 | import net.minecraft.world.item.Item;
|
| 13 | import net.minecraft.world.item.ItemStack;
|
| 14 | import net.minecraft.world.item.ItemStackTemplate;
|
| 15 | import net.minecraft.world.item.Items;
|
| 16 | import net.minecraft.world.level.Level;
|
| 17 | import net.minecraft.world.phys.EntityHitResult;
|
| 18 | import net.minecraft.world.phys.HitResult;
|
| 19 |
|
| 20 | public class Snowball extends ThrowableItemProjectile {
|
| 21 | public Snowball(final EntityType<? extends Snowball> type, final Level level) {
|
| 22 | super(type, level);
|
| 23 | }
|
| 24 |
|
| 25 | public Snowball(final Level level, final LivingEntity mob, final ItemStack itemStack) {
|
| 26 | super(EntityTypes.SNOWBALL, mob, level, itemStack);
|
| 27 | }
|
| 28 |
|
| 29 | public Snowball(final Level level, final double x, final double y, final double z, final ItemStack itemStack) {
|
| 30 | super(EntityTypes.SNOWBALL, x, y, z, level, itemStack);
|
| 31 | }
|
| 32 |
|
| 33 | @Override
|
| 34 | protected Item getDefaultItem() {
|
| 35 | return Items.SNOWBALL;
|
| 36 | }
|
| 37 |
|
| 38 | private ParticleOptions getParticle() {
|
| 39 | ItemStack item = this.getItem();
|
| 40 | return item.isEmpty() ? ParticleTypes.ITEM_SNOWBALL : new ItemParticleOption(ParticleTypes.ITEM, ItemStackTemplate.fromNonEmptyStack(item));
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public void handleEntityEvent(final @EntityEvent.Value byte id) {
|
| 45 | if (id == 3) {
|
| 46 | ParticleOptions particle = this.getParticle();
|
| 47 |
|
| 48 | for (int i = 0; i < 8; i++) {
|
| 49 | this.level().addParticle(particle, this.getX(), this.getY(), this.getZ(), 0.0, 0.0, 0.0);
|
| 50 | }
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | @Override
|
| 55 | protected void onHitEntity(final EntityHitResult hitResult) {
|
| 56 | super.onHitEntity(hitResult);
|
| 57 | Entity entity = hitResult.getEntity();
|
| 58 | int damage = entity instanceof Blaze ? 3 : 0;
|
| 59 | entity.hurt(this.damageSources().thrown(this, this.getOwner()), damage);
|
| 60 | }
|
| 61 |
|
| 62 | @Override
|
| 63 | protected void onHit(final HitResult hitResult) {
|
| 64 | super.onHit(hitResult);
|
| 65 | if (!this.level().isClientSide()) {
|
| 66 | this.level().broadcastEntityEvent(this, (byte)3);
|
| 67 | this.discard();
|
| 68 | }
|
| 69 | }
|
| 70 | }
|
| 71 |
|