diff --git a/projects/pswg_gadgets/src/client/java/dev/pswg/GadgetsClient.java b/projects/pswg_gadgets/src/client/java/dev/pswg/GadgetsClient.java index 05458cd89..59a087edf 100644 --- a/projects/pswg_gadgets/src/client/java/dev/pswg/GadgetsClient.java +++ b/projects/pswg_gadgets/src/client/java/dev/pswg/GadgetsClient.java @@ -3,6 +3,7 @@ import dev.pswg.api.GalaxiesClientAddon; import dev.pswg.particles.FragmentationGrenadeSparkParticle; import dev.pswg.particles.ExplosionSmokeParticle; +import dev.pswg.particles.FragmentationGrenadeWaveParticle; import dev.pswg.renderer.FragmentationGrenadeEntityRenderer; import dev.pswg.renderer.ThermalDetonatorEntityRenderer; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; @@ -24,6 +25,7 @@ public void onGalaxiesClientReady() ParticleFactoryRegistry.getInstance().register(Gadgets.EXPLOSION_SMOKE_PARTICLE, ExplosionSmokeParticle.Factory::new); ParticleFactoryRegistry.getInstance().register(Gadgets.FRAGMENTATION_GRENADE_SPARK, FragmentationGrenadeSparkParticle.Factory::new); + ParticleFactoryRegistry.getInstance().register(Gadgets.FRAGMENTATION_GRENADE_WAVE, FragmentationGrenadeWaveParticle.Factory::new); Gadgets.LOGGER.info("Client module initialized"); } diff --git a/projects/pswg_gadgets/src/client/java/dev/pswg/datagen/GadgetsDataGenerator.java b/projects/pswg_gadgets/src/client/java/dev/pswg/datagen/GadgetsDataGenerator.java index 1b3220f1b..3e041ae2d 100644 --- a/projects/pswg_gadgets/src/client/java/dev/pswg/datagen/GadgetsDataGenerator.java +++ b/projects/pswg_gadgets/src/client/java/dev/pswg/datagen/GadgetsDataGenerator.java @@ -121,7 +121,10 @@ protected void configure(RegistryWrapper.WrapperLookup wrapperLookup) .add(Blocks.FERN) .add(Blocks.LARGE_FERN) .add(Blocks.BROWN_MUSHROOM) - .add(Blocks.RED_MUSHROOM); + .add(Blocks.RED_MUSHROOM) + .add(Blocks.DEAD_BUSH) + .add(Blocks.SHORT_GRASS) + .add(Blocks.TALL_GRASS); getOrCreateTagBuilder(Gadgets.DETONATES_GRENADE) .add(Blocks.REDSTONE_BLOCK) diff --git a/projects/pswg_gadgets/src/client/java/dev/pswg/particles/FragmentationGrenadeWaveParticle.java b/projects/pswg_gadgets/src/client/java/dev/pswg/particles/FragmentationGrenadeWaveParticle.java new file mode 100644 index 000000000..2f0e438d2 --- /dev/null +++ b/projects/pswg_gadgets/src/client/java/dev/pswg/particles/FragmentationGrenadeWaveParticle.java @@ -0,0 +1,137 @@ +package dev.pswg.particles; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.particle.*; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.particle.SimpleParticleType; +import net.minecraft.text.Text; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.math.random.Random; +import org.jetbrains.annotations.Nullable; +import org.joml.Quaternionf; +import org.joml.Vector3f; + +@Environment(value = EnvType.CLIENT) +public class FragmentationGrenadeWaveParticle extends SpriteBillboardParticle +{ + private float scaleX = 1; + private float scaleY = 1; + + protected FragmentationGrenadeWaveParticle(ClientWorld clientWorld, double x, double y, double z, double vX, double vY, double vZ, SpriteProvider spriteProvider) + { + super(clientWorld, x, y, z); + setBoundingBoxSpacing(0.25f, 0.25f); + this.collidesWithWorld = false; + velocityX = vX; + velocityY = vY + (double)(random.nextFloat() / 500.0f); + velocityZ = vZ; + this.maxAge = 20; + this.scale = 1; + this.setSprite(spriteProvider); + this.setColor(Random.create().nextBetween(0, 2) / 2f + 0.98f, Random.create().nextBetween(0, 2) / 2f + 0.98f, 1); + } + + private void updateShape(float age) + { + if (age <= 10) + { + this.alpha = 1; + + this.scaleX = 2 * (1 + 2 * (float)Math.max(4 * Math.pow(age / 10 - 0.5f, 3), 0)); + this.scaleY = 2 * (1 - (float)Math.pow((age - 4) / 6, 2)); + } + else + { + this.scaleX = this.scaleY = 1; + this.scale = (float)Math.pow(age / 10, 6); + this.alpha = (float)(Math.max(1 - (Math.pow(age / 20, 3) * 2), 0.001f)); + } + } + + @Override + public ParticleTextureSheet getType() + { + return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT; + } + + @Override + public void render(VertexConsumer vertexConsumer, Camera camera, float tickDelta) + { + updateShape(this.age + tickDelta); + + Vec3d vec3d = camera.getPos(); + float f = (float)(MathHelper.lerp((double)tickDelta, this.prevPosX, this.x) - vec3d.getX()); + float g = (float)(MathHelper.lerp((double)tickDelta, this.prevPosY, this.y) - vec3d.getY()); + float h = (float)(MathHelper.lerp((double)tickDelta, this.prevPosZ, this.z) - vec3d.getZ()); + + Quaternionf quaternionf = new Quaternionf(); + this.getRotator().setRotation(quaternionf, camera, tickDelta); + if (this.angle != 0.0F) + { + quaternionf.rotateZ(MathHelper.lerp(tickDelta, this.prevAngle, this.angle)); + } + + Vector3f[] corners = new Vector3f[] { + new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F) + }; + float size = this.getSize(tickDelta); + + for (int j = 0; j < 4; ++j) + { + Vector3f vector3f = corners[j]; + vector3f.mul(scaleX, scaleY, 1); + vector3f.rotate(new Quaternionf(camera.getRotation().rotateZ((float)Math.toRadians(180d)))); + vector3f.mul(size); + vector3f.add(f, g, h); + } + + float k = this.getMinU(); + float l = this.getMaxU(); + float m = this.getMinV(); + float n = this.getMaxV(); + int o = this.getBrightness(tickDelta); + vertexConsumer.vertex(corners[0].x(), corners[0].y(), corners[0].z()) + .texture(l, n) + .color(this.red, this.green, this.blue, this.alpha) + .light(o); + vertexConsumer.vertex(corners[1].x(), corners[1].y(), corners[1].z()) + .texture(l, m) + .color(this.red, this.green, this.blue, this.alpha) + .light(o); + vertexConsumer.vertex(corners[2].x(), corners[2].y(), corners[2].z()) + .texture(k, m) + .color(this.red, this.green, this.blue, this.alpha) + .light(o); + vertexConsumer.vertex(corners[3].x(), corners[3].y(), corners[3].z()) + .texture(k, n) + .color(this.red, this.green, this.blue, this.alpha) + .light(o); + } + + @Environment(value = EnvType.CLIENT) + public static class Factory implements ParticleFactory + { + private final SpriteProvider spriteProvider; + + public Factory(SpriteProvider spriteProvider) + { + this.spriteProvider = spriteProvider; + } + + @Nullable + @Override + public Particle createParticle(SimpleParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) + { + FragmentationGrenadeWaveParticle fragmentationGrenadeParticle = new FragmentationGrenadeWaveParticle(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider); + fragmentationGrenadeParticle.setSprite(spriteProvider); + return fragmentationGrenadeParticle; + } + } +} diff --git a/projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java b/projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java index 3380228ad..ebb080765 100644 --- a/projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java +++ b/projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java @@ -90,6 +90,7 @@ public static Identifier id(String path) public static final SimpleParticleType EXPLOSION_SMOKE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("explosion_smoke"), FabricParticleTypes.simple()); public static final SimpleParticleType FRAGMENTATION_GRENADE_SPARK = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_spark"), FabricParticleTypes.simple()); + public static final SimpleParticleType FRAGMENTATION_GRENADE_WAVE = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_wave"), FabricParticleTypes.simple()); public static final SoundEvent ARM = registerSound(id("shared.arm")); public static final SoundEvent DISARM = registerSound(id("shared.disarm")); diff --git a/projects/pswg_gadgets/src/main/java/dev/pswg/entity/FragmentationGrenadeEntity.java b/projects/pswg_gadgets/src/main/java/dev/pswg/entity/FragmentationGrenadeEntity.java index 0d09963b8..2be08d42e 100644 --- a/projects/pswg_gadgets/src/main/java/dev/pswg/entity/FragmentationGrenadeEntity.java +++ b/projects/pswg_gadgets/src/main/java/dev/pswg/entity/FragmentationGrenadeEntity.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.util.ActionResult; @@ -37,6 +38,7 @@ public FragmentationGrenadeEntity(EntityType type, W setExplosionPower(4f); } + @Override public GrenadeItem getItem() { @@ -54,8 +56,7 @@ public void explode() { if (getWorld() instanceof ServerWorld serverWorld) { - //for (ServerPlayerEntity serverPlayerEntity : serverWorld.getPlayers()) - // serverWorld.spawnParticles(serverPlayerEntity, SwgParticleTypes.FRAGMENTATION_GRENADE, true, getX(), getY(), getZ(), 1, 0, 0, 0, 0); + serverWorld.spawnParticles(Gadgets.FRAGMENTATION_GRENADE_WAVE, false, true, getX(), getY() + 0.05d, getZ(), 1, 0, 0, 0, 0); var passedData = new PacketByteBuf(Unpooled.buffer()); passedData.writeBoolean(true); passedData.writeInt(getId()); @@ -120,7 +121,7 @@ public void tick() if (EXPLOSION_TICK == 7) { - for (int i = 0; i < Random.create().nextBetween(50, 80); i++) + for (int i = 0; i < Random.create().nextBetween(70, 100); i++) { double vx = getWorld().random.nextGaussian() * 0.5; double vz = getWorld().random.nextGaussian() * 0.5; diff --git a/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/particles/fragmentation_grenade_wave.json b/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/particles/fragmentation_grenade_wave.json new file mode 100644 index 000000000..450e27a55 --- /dev/null +++ b/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/particles/fragmentation_grenade_wave.json @@ -0,0 +1,5 @@ +{ + "textures": [ + "pswg_gadgets:fragmentation_grenade_wave" + ] +} \ No newline at end of file diff --git a/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/textures/particle/fragmentation_grenade_wave.png b/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/textures/particle/fragmentation_grenade_wave.png new file mode 100644 index 000000000..bb90468ca Binary files /dev/null and b/projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/textures/particle/fragmentation_grenade_wave.png differ