| 1 | package net.minecraft.world.entity.projectile.hurtingprojectile.windcharge;
|
| 2 |
|
| 3 | import java.util.Optional;
|
| 4 | import java.util.function.Function;
|
| 5 | import net.minecraft.core.Vec3i;
|
| 6 | import net.minecraft.core.particles.ParticleOptions;
|
| 7 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 8 | import net.minecraft.server.level.ServerLevel;
|
| 9 | import net.minecraft.tags.BlockTags;
|
| 10 | import net.minecraft.world.damagesource.DamageSource;
|
| 11 | import net.minecraft.world.entity.Entity;
|
| 12 | import net.minecraft.world.entity.EntityType;
|
| 13 | import net.minecraft.world.entity.EntityTypes;
|
| 14 | import net.minecraft.world.entity.LivingEntity;
|
| 15 | import net.minecraft.world.entity.projectile.ItemSupplier;
|
| 16 | import net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile;
|
| 17 | import net.minecraft.world.item.ItemStack;
|
| 18 | import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
| 19 | import net.minecraft.world.level.ExplosionDamageCalculator;
|
| 20 | import net.minecraft.world.level.Level;
|
| 21 | import net.minecraft.world.level.SimpleExplosionDamageCalculator;
|
| 22 | import net.minecraft.world.phys.AABB;
|
| 23 | import net.minecraft.world.phys.BlockHitResult;
|
| 24 | import net.minecraft.world.phys.EntityHitResult;
|
| 25 | import net.minecraft.world.phys.HitResult;
|
| 26 | import net.minecraft.world.phys.Vec3;
|
| 27 | import org.jspecify.annotations.Nullable;
|
| 28 |
|
| 29 | public abstract class AbstractWindCharge extends AbstractHurtingProjectile implements ItemSupplier {
|
| 30 | public static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new SimpleExplosionDamageCalculator(
|
| 31 | true, false, Optional.empty(), BuiltInRegistries.BLOCK.get(BlockTags.BLOCKS_WIND_CHARGE_EXPLOSIONS).map(Function.identity())
|
| 32 | );
|
| 33 | public static final double JUMP_SCALE = 0.25;
|
| 34 |
|
| 35 | public AbstractWindCharge(final EntityType<? extends AbstractWindCharge> type, final Level level) {
|
| 36 | super(type, level);
|
| 37 | this.accelerationPower = 0.0;
|
| 38 | }
|
| 39 |
|
| 40 | public AbstractWindCharge(
|
| 41 | final EntityType<? extends AbstractWindCharge> type, final Level level, final Entity owner, final double x, final double y, final double z
|
| 42 | ) {
|
| 43 | super(type, x, y, z, level);
|
| 44 | this.setOwner(owner);
|
| 45 | this.accelerationPower = 0.0;
|
| 46 | }
|
| 47 |
|
| 48 | protected AbstractWindCharge(
|
| 49 | final EntityType<? extends AbstractWindCharge> type, final double x, final double y, final double z, final Vec3 direction, final Level level
|
| 50 | ) {
|
| 51 | super(type, x, y, z, direction, level);
|
| 52 | this.accelerationPower = 0.0;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected AABB makeBoundingBox(final Vec3 position) {
|
| 57 | float width = this.getType().getDimensions().width() / 2.0F;
|
| 58 | float height = this.getType().getDimensions().height();
|
| 59 | float offset = 0.15F;
|
| 60 | return new AABB(position.x - width, position.y - 0.15F, position.z - width, position.x + width, position.y - 0.15F + height, position.z + width);
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public boolean canCollideWith(final Entity entity) {
|
| 65 | return entity instanceof AbstractWindCharge ? false : super.canCollideWith(entity);
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | protected boolean canHitEntity(final Entity entity) {
|
| 70 | if (entity instanceof AbstractWindCharge) {
|
| 71 | return false;
|
| 72 | } else {
|
| 73 | return entity.is(EntityTypes.END_CRYSTAL) ? false : super.canHitEntity(entity);
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | protected void onHitEntity(final EntityHitResult hitResult) {
|
| 79 | super.onHitEntity(hitResult);
|
| 80 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 81 | LivingEntity owner = this.getOwner() instanceof LivingEntity entity ? entity : null;
|
| 82 | Entity entity = hitResult.getEntity();
|
| 83 | if (owner != null) {
|
| 84 | owner.setLastHurtMob(entity);
|
| 85 | }
|
| 86 |
|
| 87 | DamageSource source = this.damageSources().windCharge(this, owner);
|
| 88 | if (entity.hurtServer(serverLevel, source, 1.0F) && entity instanceof LivingEntity mob) {
|
| 89 | EnchantmentHelper.doPostAttackEffects(serverLevel, mob, source);
|
| 90 | }
|
| 91 |
|
| 92 | this.explode(this.position());
|
| 93 | }
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | public void push(final double xa, final double ya, final double za) {
|
| 98 | }
|
| 99 |
|
| 100 | protected abstract void explode(final Vec3 position);
|
| 101 |
|
| 102 | @Override
|
| 103 | protected void onHitBlock(final BlockHitResult hitResult) {
|
| 104 | super.onHitBlock(hitResult);
|
| 105 | if (!this.level().isClientSide()) {
|
| 106 | Vec3i collisionNormal = hitResult.getDirection().getUnitVec3i();
|
| 107 | Vec3 scaledNormal = Vec3.atLowerCornerOf(collisionNormal).multiply(0.25, 0.25, 0.25);
|
| 108 | Vec3 explosionPos = hitResult.getLocation().add(scaledNormal);
|
| 109 | this.explode(explosionPos);
|
| 110 | this.discard();
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | @Override
|
| 115 | protected void onHit(final HitResult hitResult) {
|
| 116 | super.onHit(hitResult);
|
| 117 | if (!this.level().isClientSide()) {
|
| 118 | this.discard();
|
| 119 | }
|
| 120 | }
|
| 121 |
|
| 122 | @Override
|
| 123 | protected boolean shouldBurn() {
|
| 124 | return false;
|
| 125 | }
|
| 126 |
|
| 127 | @Override
|
| 128 | public ItemStack getItem() {
|
| 129 | return ItemStack.EMPTY;
|
| 130 | }
|
| 131 |
|
| 132 | @Override
|
| 133 | protected float getInertia() {
|
| 134 | return 1.0F;
|
| 135 | }
|
| 136 |
|
| 137 | @Override
|
| 138 | protected float getLiquidInertia() {
|
| 139 | return this.getInertia();
|
| 140 | }
|
| 141 |
|
| 142 | @Override
|
| 143 | protected @Nullable ParticleOptions getTrailParticle() {
|
| 144 | return null;
|
| 145 | }
|
| 146 |
|
| 147 | @Override
|
| 148 | public void tick() {
|
| 149 | if (!this.level().isClientSide() && this.getBlockY() > this.level().getMaxY() + 30) {
|
| 150 | this.explode(this.position());
|
| 151 | this.discard();
|
| 152 | } else {
|
| 153 | super.tick();
|
| 154 | }
|
| 155 | }
|
| 156 | }
|
| 157 |
|