Use the lightning particle instead of lightning entities

This commit is contained in:
Sollace 2021-12-28 02:20:08 +02:00
parent f1c4d8301e
commit 75fbfb9c11
9 changed files with 36 additions and 12 deletions

View file

@ -162,7 +162,7 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileSpel
world.playSound(null, pos, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.AMBIENT, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
for (int i = 0; i < 8; ++i) {
ParticleUtils.spawnParticle(ParticleTypes.LARGE_SMOKE, world, new Vec3d(
ParticleUtils.spawnParticle(world, ParticleTypes.LARGE_SMOKE, new Vec3d(
x + Math.random(),
y + Math.random(),
z + Math.random()

View file

@ -46,7 +46,7 @@ public class IceSpell extends AbstractSpell {
PosHelper.getAllInRegionMutable(source.getOrigin(), effect_range)
.forEach(i -> {
if (applyBlockSingle(owner, source.getWorld(), i)) {
ParticleUtils.spawnParticle(ParticleTypes.SPLASH, source.getWorld(), new Vec3d(
ParticleUtils.spawnParticle(source.getWorld(), ParticleTypes.SPLASH, new Vec3d(
i.getX() + source.getWorld().random.nextFloat(),
i.getY() + 1,
i.getZ() + source.getWorld().random.nextFloat()), Vec3d.ZERO);

View file

@ -102,7 +102,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell {
}
} else {
e.heal((float)Math.min(0.5F * (1 + source.getLevel().get()), maxHealthGain * 0.6));
ParticleUtils.spawnParticle(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, e, 0.2F), e.world, e.getPos(), Vec3d.ZERO);
ParticleUtils.spawnParticle(e.world, new FollowingParticleEffect(UParticles.HEALTH_DRAIN, e, 0.2F), e.getPos(), Vec3d.ZERO);
}
});
}

View file

@ -34,7 +34,7 @@ public class CloudsEscapingParticle extends GroundPoundParticle {
.offset(center)
.randomPoints(random)
.forEach(point -> {
ParticleUtils.spawnParticle(ParticleTypes.CLOUD, world, point, vel);
ParticleUtils.spawnParticle(world, ParticleTypes.CLOUD, point, vel);
});
}
}

View file

@ -56,7 +56,7 @@ public class GroundPoundParticle extends Particle {
}
}
ParticleUtils.spawnParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, state), world, point, vel);
ParticleUtils.spawnParticle(world, new BlockStateParticleEffect(ParticleTypes.BLOCK, state), point, vel);
});
}
}

View file

@ -8,10 +8,13 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.ai.FuzzyPositions;
@ -29,6 +32,7 @@ import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
@ -36,6 +40,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
public class FairyEntity extends PathAwareEntity implements LightEmittingEntity, Owned<LivingEntity> {
private final EntityReference<LivingEntity> owner = new EntityReference<>();
@ -199,7 +204,13 @@ public class FairyEntity extends PathAwareEntity implements LightEmittingEntity,
@Override
public boolean handleAttack(Entity attacker) {
attacker.damage(DamageSource.LIGHTNING_BOLT, (float)getAttackDistanceScalingFactor(attacker) * 3);
if (world instanceof ServerWorld) {
LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world);
lightning.refreshPositionAfterTeleport(getX(), getY(), getZ());
attacker.onStruckByLightning((ServerWorld)world, lightning);
}
emitGameEvent(GameEvent.LIGHTNING_STRIKE);
ParticleUtils.spawnParticle(world, UParticles.LIGHTNING_BOLT, getPos(), Vec3d.ZERO);
return false;
}

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.entity.IItemEntity;
import com.minelittlepony.unicopia.entity.ItemImpl;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
@ -25,6 +26,7 @@ import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldEvents;
import net.minecraft.world.level.ServerWorldProperties;
@ -139,6 +141,10 @@ public class JarItem extends Item implements ProjectileDelegate, ItemImpl.Tickab
}
}
if (lightning) {
ParticleUtils.spawnParticle(projectile.world, UParticles.LIGHTNING_BOLT, projectile.getPos(), Vec3d.ZERO);
}
if (rain || thunder) {
projectile.world.syncWorldEvent(WorldEvents.SPLASH_POTION_SPLASHED, projectile.getBlockPos(), thunder ? 0x888888 : 0xF8F8F8);

View file

@ -1,11 +1,12 @@
package com.minelittlepony.unicopia.item;
import java.util.Optional;
import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.advancement.UCriteria;
import com.minelittlepony.unicopia.item.toxin.Toxicity;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.util.MagicalDamageSource;
import com.minelittlepony.unicopia.util.RayTraceHelper;
import net.minecraft.entity.Entity;
@ -24,11 +25,13 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.Hand;
import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
public class ZapAppleItem extends AppleItem implements ChameleonItem {
@ -59,12 +62,16 @@ public class ZapAppleItem extends AppleItem implements ChameleonItem {
LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(w);
lightning.refreshPositionAfterTeleport(player.getX(), player.getY(), player.getZ());
w.spawnEntity(lightning);
player.onStruckByLightning((ServerWorld)w, lightning);
if (player instanceof PlayerEntity) {
UCriteria.EAT_TRICK_APPLE.trigger((PlayerEntity)player);
}
}
player.emitGameEvent(GameEvent.LIGHTNING_STRIKE);
ParticleUtils.spawnParticle(w, UParticles.LIGHTNING_BOLT, player.getPos(), Vec3d.ZERO);
return stack;
}

View file

@ -14,14 +14,14 @@ import net.minecraft.world.World;
*/
public final class ParticleUtils {
public static void spawnParticles(ParticleEffect particleId, Entity entity, int count) {
public static void spawnParticles(ParticleEffect effect, Entity entity, int count) {
double halfDist = Math.abs(entity.getStandingEyeHeight() / 1.5);
double middle = entity.getBoundingBox().minY + halfDist;
Shape shape = new Sphere(false, Math.abs((float)halfDist + entity.getWidth()));
shape.randomPoints(count, entity.world.random).forEach(point -> {
spawnParticle(entity.world, particleId,
spawnParticle(entity.world, effect,
entity.getX() + point.x,
middle + point.y,
entity.getZ() + point.z,
@ -29,8 +29,8 @@ public final class ParticleUtils {
});
}
public static void spawnParticle(ParticleEffect particleId, World world, Vec3d pos, Vec3d vel) {
spawnParticle(world, particleId, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z);
public static void spawnParticle(World world, ParticleEffect effect, Vec3d pos, Vec3d vel) {
spawnParticle(world, effect, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z);
}
public static void spawnParticle(World world, ParticleEffect effect, double x, double y, double z, double vX, double vY, double vZ) {