From b9f40238fc603f7cb23208e5cc4498b34835bc0c Mon Sep 17 00:00:00 2001 From: "Josiah (Gaming32) Glosson" Date: Wed, 21 Jun 2023 18:48:53 -0500 Subject: [PATCH] Extremely basic spark particles --- .../LaserEmitterBlockEntity.java | 11 +++ .../portalcubed/client/PortalCubedClient.java | 4 +- .../client/particle/DecalParticle.java | 4 +- .../client/particle/EnergySparkParticle.java | 88 ++++++++++++++++++ ...java => PortalCubedParticleProviders.java} | 9 +- .../entity/EnergyPelletEntity.java | 17 +++- .../portalcubed/entity/TurretEntity.java | 15 ++- .../particle/PortalCubedParticleTypes.java | 7 ++ .../portalcubed/particles/energy_spark.json | 5 + .../textures/particle/energy_spark.png | Bin 0 -> 84 bytes 10 files changed, 146 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/fusionflux/portalcubed/client/particle/EnergySparkParticle.java rename src/main/java/com/fusionflux/portalcubed/client/particle/{PortalCubedParticleFactories.java => PortalCubedParticleProviders.java} (59%) create mode 100644 src/main/resources/assets/portalcubed/particles/energy_spark.json create mode 100644 src/main/resources/assets/portalcubed/textures/particle/energy_spark.png diff --git a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java index ec244f1b..bfbe9928 100644 --- a/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/blocks/blockentities/LaserEmitterBlockEntity.java @@ -3,9 +3,11 @@ import com.fusionflux.portalcubed.PortalCubedConfig; import com.fusionflux.portalcubed.blocks.LaserCatcherBlock; import com.fusionflux.portalcubed.blocks.LaserEmitterBlock; +import com.fusionflux.portalcubed.blocks.LaserRelayBlock; import com.fusionflux.portalcubed.blocks.PortalCubedBlocks; import com.fusionflux.portalcubed.entity.CorePhysicsEntity; import com.fusionflux.portalcubed.entity.RedirectionCubeEntity; +import com.fusionflux.portalcubed.particle.PortalCubedParticleTypes; import com.fusionflux.portalcubed.sound.PortalCubedSounds; import com.fusionflux.portalcubed.util.AdvancedEntityRaycast; import com.fusionflux.portalcubed.util.GeneralUtil; @@ -20,6 +22,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -156,6 +159,14 @@ public void tick(Level level, BlockPos pos, BlockState state) { return; } + if (hitState != null && !(hitState.getBlock() instanceof LaserRelayBlock)) { + final Vec3 finalPos = multiSegments.get(multiSegments.size() - 1).finalRay().end(); + ((ServerLevel)level).sendParticles( + PortalCubedParticleTypes.ENERGY_SPARK, + finalPos.x, finalPos.y, finalPos.z, 5, 0, 0, 0, 0.01 + ); + } + Entity owner = EntityType.MARKER.create(level); assert owner != null; alreadyHit.clear(); diff --git a/src/main/java/com/fusionflux/portalcubed/client/PortalCubedClient.java b/src/main/java/com/fusionflux/portalcubed/client/PortalCubedClient.java index bbde2844..1b787777 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/PortalCubedClient.java +++ b/src/main/java/com/fusionflux/portalcubed/client/PortalCubedClient.java @@ -11,7 +11,7 @@ import com.fusionflux.portalcubed.client.gui.FaithPlateScreen; import com.fusionflux.portalcubed.client.gui.VelocityHelperScreen; import com.fusionflux.portalcubed.client.packet.PortalCubedClientPackets; -import com.fusionflux.portalcubed.client.particle.PortalCubedParticleFactories; +import com.fusionflux.portalcubed.client.particle.PortalCubedParticleProviders; import com.fusionflux.portalcubed.client.render.PortalHud; import com.fusionflux.portalcubed.client.render.block.EmissiveSpriteRegistry; import com.fusionflux.portalcubed.client.render.block.entity.*; @@ -158,7 +158,7 @@ public void onInitializeClient(ModContainer mod) { registerEmissiveModels(mod); PortalCubedClientPackets.registerPackets(); PortalCubedKeyBindings.register(); - PortalCubedParticleFactories.register(); + PortalCubedParticleProviders.register(); HudRenderCallback.EVENT.register(PortalHud::renderPortalRight); HudRenderCallback.EVENT.register(PortalHud::renderPortalLeft); diff --git a/src/main/java/com/fusionflux/portalcubed/client/particle/DecalParticle.java b/src/main/java/com/fusionflux/portalcubed/client/particle/DecalParticle.java index d654bffa..d827997c 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/particle/DecalParticle.java +++ b/src/main/java/com/fusionflux/portalcubed/client/particle/DecalParticle.java @@ -127,13 +127,13 @@ public ParticleRenderType getRenderType() { } @ClientOnly - public static class Factory implements ParticleProvider { + public static class Provider implements ParticleProvider { private final FabricSpriteProvider spriteProvider; private List cacheKey; private final Map spriteCache = new HashMap<>(); - public Factory(FabricSpriteProvider spriteProvider) { + public Provider(FabricSpriteProvider spriteProvider) { this.spriteProvider = spriteProvider; } diff --git a/src/main/java/com/fusionflux/portalcubed/client/particle/EnergySparkParticle.java b/src/main/java/com/fusionflux/portalcubed/client/particle/EnergySparkParticle.java new file mode 100644 index 00000000..b21a237c --- /dev/null +++ b/src/main/java/com/fusionflux/portalcubed/client/particle/EnergySparkParticle.java @@ -0,0 +1,88 @@ +package com.fusionflux.portalcubed.client.particle; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.Camera; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleRenderType; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.util.Mth; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; +import org.quiltmc.loader.api.minecraft.ClientOnly; + +@ClientOnly +public class EnergySparkParticle extends Particle { + private double xoo, yoo, zoo; + + public EnergySparkParticle( + ClientLevel clientLevel, + double x, double y, double z, + double xSpeed, double ySpeed, double zSpeed + ) { + super(clientLevel, x, y, z, xSpeed, ySpeed, zSpeed); + xoo = x; + yoo = y; + zoo = z; + friction = 1f; + gravity = 0.8f; + lifetime *= 4; + } + + @Override + public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) { + final PoseStack poseStack = new PoseStack(); + final Vec3 position = renderInfo.getPosition(); + poseStack.translate(-position.x, -position.y, -position.z); + final MultiBufferSource.BufferSource bufferSource = Minecraft.getInstance().renderBuffers().bufferSource(); + final VertexConsumer vertexConsumer = bufferSource.getBuffer(RenderType.lines()); + render0(poseStack, vertexConsumer, partialTicks); + bufferSource.endBatch(); + } + + private void render0(PoseStack poseStack, VertexConsumer vertexConsumer, float partialTicks) { + final float x1 = (float)Mth.lerp(partialTicks, xoo, xo); + final float y1 = (float)Mth.lerp(partialTicks, yoo, yo); + final float z1 = (float)Mth.lerp(partialTicks, zoo, zo); + + final float x2 = (float)Mth.lerp(partialTicks, xo, x); + final float y2 = (float)Mth.lerp(partialTicks, yo, y); + final float z2 = (float)Mth.lerp(partialTicks, zo, z); + + final float nx = x2 - x1; + final float ny = y2 - y1; + final float nz = z2 - z1; + + final PoseStack.Pose matrix = poseStack.last(); + vertexConsumer + .vertex(matrix.pose(), x1, y1, z1) + .color(242 / 255f, 177 / 255f, 46 / 255f, 1f) + .normal(matrix.normal(), nx, ny, nz) + .endVertex(); + vertexConsumer + .vertex(matrix.pose(), x2, y2, z2) + .color(97 / 255f, 67 / 255f, 6 / 255f, 1f) + .normal(matrix.normal(), nx, ny, nz) + .endVertex(); + } + + @NotNull + @Override + public ParticleRenderType getRenderType() { + return ParticleRenderType.CUSTOM; + } + + @Override + public void tick() { + xoo = xo; + yoo = yo; + zoo = zo; + super.tick(); + if (onGround) { + yd = -yd * 0.75; + } + } +} diff --git a/src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleFactories.java b/src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleProviders.java similarity index 59% rename from src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleFactories.java rename to src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleProviders.java index 3eb7f09f..4c54d8e0 100644 --- a/src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleFactories.java +++ b/src/main/java/com/fusionflux/portalcubed/client/particle/PortalCubedParticleProviders.java @@ -5,9 +5,14 @@ import org.quiltmc.loader.api.minecraft.ClientOnly; @ClientOnly -public class PortalCubedParticleFactories { +public class PortalCubedParticleProviders { public static void register() { final ParticleFactoryRegistry registry = ParticleFactoryRegistry.getInstance(); - registry.register(PortalCubedParticleTypes.DECAL, DecalParticle.Factory::new); + registry.register(PortalCubedParticleTypes.DECAL, DecalParticle.Provider::new); + registry.register( + PortalCubedParticleTypes.ENERGY_SPARK, + sprites -> (type, level, x, y, z, xSpeed, ySpeed, zSpeed) -> + new EnergySparkParticle(level, x, y, z, xSpeed, ySpeed, zSpeed) + ); } } diff --git a/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java index bfe3e875..dd40c2f8 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/EnergyPelletEntity.java @@ -4,6 +4,7 @@ import com.fusionflux.portalcubed.items.PortalCubedItems; import com.fusionflux.portalcubed.listeners.WentThroughPortalListener; import com.fusionflux.portalcubed.particle.DecalParticleOption; +import com.fusionflux.portalcubed.particle.PortalCubedParticleTypes; import com.fusionflux.portalcubed.sound.PortalCubedSounds; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -114,19 +115,23 @@ public void tick() { if (bouncedDir != null) { setDeltaMovement(vel); level.playSound(null, this, PortalCubedSounds.PELLET_BOUNCE_EVENT, SoundSource.HOSTILE, 0.4f, 1f); - if (level instanceof ServerLevel serverWorld) { - final Vec3 spawnPos = serverWorld.clip(new ClipContext( + if (level instanceof ServerLevel serverLevel) { + final Vec3 spawnPos = serverLevel.clip(new ClipContext( position(), position().add(vel.with(bouncedDir.getAxis(), -vel.get(bouncedDir.getAxis()))), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this )).getLocation().add(Vec3.atLowerCornerOf(bouncedDir.getNormal()).scale(0.01)); - serverWorld.sendParticles( + serverLevel.sendParticles( new DecalParticleOption(DecalParticleOption.SCORCH, bouncedDir), spawnPos.x, spawnPos.y, spawnPos.z, 0, 0, 0, 0, 0 ); + serverLevel.sendParticles( + PortalCubedParticleTypes.ENERGY_SPARK, + getX(), getY(), getZ(), 25, 0.1, 0.1, 0.1, 1 + ); } } if ((tickCount - 1) % 34 == 0) { @@ -177,6 +182,12 @@ private void bounceOrKill(LivingEntity entity) { private void kill(@Nullable LivingEntity entity) { level.playSound(null, position().x, position().y, position().z, PortalCubedSounds.PELLET_EXPLODE_EVENT, SoundSource.HOSTILE, 0.8f, 1f); + if (level instanceof ServerLevel serverLevel) { + serverLevel.sendParticles( + PortalCubedParticleTypes.ENERGY_SPARK, + getX(), getY(), getZ(), 100, 0.1, 0.1, 0.1, 3.5 + ); + } if (entity != null) { entity.hurt(pcSources(level).vaporization(), PortalCubedConfig.pelletDamage); } diff --git a/src/main/java/com/fusionflux/portalcubed/entity/TurretEntity.java b/src/main/java/com/fusionflux/portalcubed/entity/TurretEntity.java index f48f2620..e9d52c10 100644 --- a/src/main/java/com/fusionflux/portalcubed/entity/TurretEntity.java +++ b/src/main/java/com/fusionflux/portalcubed/entity/TurretEntity.java @@ -3,6 +3,7 @@ import com.fusionflux.portalcubed.blocks.PortalCubedBlocks; import com.fusionflux.portalcubed.compat.rayon.RayonIntegration; import com.fusionflux.portalcubed.particle.DecalParticleOption; +import com.fusionflux.portalcubed.particle.PortalCubedParticleTypes; import com.fusionflux.portalcubed.sound.PortalCubedSounds; import com.fusionflux.portalcubed.util.GeneralUtil; import net.minecraft.core.Direction; @@ -104,8 +105,8 @@ public void setPitchSpeed(float pitchSpeed) { getEntityData().set(PITCH_SPEED, pitchSpeed); } - public static void makeBulletHole(ServerLevel world, BlockHitResult hit, SoundSource soundCategory) { - final BlockState block = world.getBlockState(hit.getBlockPos()); + public static void makeBulletHole(ServerLevel level, BlockHitResult hit, SoundSource soundCategory) { + final BlockState block = level.getBlockState(hit.getBlockPos()); final Vec3 pos = hit.getLocation().add(Vec3.atLowerCornerOf(hit.getDirection().getNormal()).scale(0.01)); final SoundEvent soundEffect; final ResourceLocation particleTexture; @@ -113,7 +114,7 @@ public static void makeBulletHole(ServerLevel world, BlockHitResult hit, SoundSo if (block.is(PortalCubedBlocks.BULLET_HOLE_CONCRETE)) { soundEffect = PortalCubedSounds.BULLET_CONCRETE_EVENT; particleTexture = DecalParticleOption.BULLET_HOLE_CONCRETE; - world.sendParticles( + level.sendParticles( new BlockParticleOption(ParticleTypes.BLOCK, block), pos.x, pos.y, pos.z, 3, 0.1, 0.1, 0.1, 1 ); @@ -124,15 +125,19 @@ public static void makeBulletHole(ServerLevel world, BlockHitResult hit, SoundSo } else if (block.is(PortalCubedBlocks.BULLET_HOLE_METAL)) { soundEffect = PortalCubedSounds.BULLET_METAL_EVENT; particleTexture = DecalParticleOption.BULLET_HOLE_METAL; + level.sendParticles( + PortalCubedParticleTypes.ENERGY_SPARK, + pos.x, pos.y, pos.z, 50, 0.1, 0.1, 0.1, 2 + ); } else { soundEffect = null; particleTexture = null; } if (soundEffect != null) { - world.playSound(null, pos.x, pos.y, pos.z, soundEffect, soundCategory, 0.3f, 1f); + level.playSound(null, pos.x, pos.y, pos.z, soundEffect, soundCategory, 0.3f, 1f); } if (particleTexture != null) { - world.sendParticles( + level.sendParticles( new DecalParticleOption(particleTexture, hit.getDirection(), multiplyTexture), pos.x, pos.y, pos.z, 0, 0, 0, 0, 0 ); diff --git a/src/main/java/com/fusionflux/portalcubed/particle/PortalCubedParticleTypes.java b/src/main/java/com/fusionflux/portalcubed/particle/PortalCubedParticleTypes.java index 70aeda20..1465609c 100644 --- a/src/main/java/com/fusionflux/portalcubed/particle/PortalCubedParticleTypes.java +++ b/src/main/java/com/fusionflux/portalcubed/particle/PortalCubedParticleTypes.java @@ -1,9 +1,11 @@ package com.fusionflux.portalcubed.particle; import com.mojang.serialization.Codec; +import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes; import net.minecraft.core.Registry; import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleType; +import net.minecraft.core.particles.SimpleParticleType; import net.minecraft.core.registries.BuiltInRegistries; import org.jetbrains.annotations.NotNull; @@ -15,6 +17,11 @@ public class PortalCubedParticleTypes { public static final ParticleType DECAL = register( "decal", false, DecalParticleOption.PARAMETERS_FACTORY, DecalParticleOption::codec ); + public static final SimpleParticleType ENERGY_SPARK = register("energy_spark", false); + + private static SimpleParticleType register(String key, boolean overrideLimiter) { + return Registry.register(BuiltInRegistries.PARTICLE_TYPE, id(key), FabricParticleTypes.simple(overrideLimiter)); + } @SuppressWarnings("deprecation") private static ParticleType register( diff --git a/src/main/resources/assets/portalcubed/particles/energy_spark.json b/src/main/resources/assets/portalcubed/particles/energy_spark.json new file mode 100644 index 00000000..acb85ef9 --- /dev/null +++ b/src/main/resources/assets/portalcubed/particles/energy_spark.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "portalcubed:energy_spark" + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/portalcubed/textures/particle/energy_spark.png b/src/main/resources/assets/portalcubed/textures/particle/energy_spark.png new file mode 100644 index 0000000000000000000000000000000000000000..64b372f6e377de6aad05a67c81e307aa8a701c68 GIT binary patch literal 84 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFq(w;7kAr*1S2@CWsN?u&3FEJF^ gQ29CS4_5{=L--%IxUPt8!9ZmUp00i_>zopr02`MU-~a#s literal 0 HcmV?d00001