Skip to content

Commit

Permalink
Neural gas particle and "pswg_particle" render layer
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jan 16, 2025
1 parent e5b943b commit b6c5e4e
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package dev.pswg;

import dev.pswg.api.GalaxiesClientAddon;
import dev.pswg.particles.FragmentationGrenadeSparkParticle;
import dev.pswg.particles.ExplosionSmokeParticle;
import dev.pswg.particles.FragmentationGrenadeWaveParticle;
import dev.pswg.particles.SmokeParticle;
import dev.pswg.particles.*;
import dev.pswg.renderer.FragmentationGrenadeEntityRenderer;
import dev.pswg.renderer.ThermalDetonatorEntityRenderer;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
Expand All @@ -28,6 +25,7 @@ public void onGalaxiesClientReady()
ParticleFactoryRegistry.getInstance().register(Gadgets.FRAGMENTATION_GRENADE_SPARK_PARTICLE, FragmentationGrenadeSparkParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(Gadgets.FRAGMENTATION_GRENADE_WAVE_PARTICLE, FragmentationGrenadeWaveParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(Gadgets.SMOKE_PARTICLE, SmokeParticle.Factory::new);
ParticleFactoryRegistry.getInstance().register(Gadgets.NEURAL_GAS_PARTICLE, NeuralGasParticle.Factory::new);

Gadgets.LOGGER.info("Client module initialized");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.pswg;

import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.TriState;
import net.minecraft.util.Util;

import java.util.function.BiFunction;

import static net.minecraft.client.render.RenderPhase.*;

public class PswgGadgetsRenderLayers
{
private static final BiFunction<Identifier, Boolean, RenderLayer> PSWG_PARTICLE = Util
.memoize((texture, affectsOutline) -> {
RenderLayer.MultiPhaseParameters multiPhaseParameters = RenderLayer.MultiPhaseParameters.builder()
.program(RenderLayer.PARTICLE)
.texture(new RenderPhase.Texture(texture, TriState.FALSE, false))
.transparency(RenderLayer.TRANSLUCENT_TRANSPARENCY).cull(DISABLE_CULLING)
.lightmap(RenderLayer.ENABLE_LIGHTMAP).overlay(ENABLE_OVERLAY_COLOR).layering(VIEW_OFFSET_Z_LAYERING)
.writeMaskState(RenderLayer.ALL_MASK).build(true);
return RenderLayer.of("pswg_particle",
VertexFormats.POSITION_TEXTURE_COLOR_LIGHT, VertexFormat.DrawMode.QUADS, 1536,
false, true, multiPhaseParameters);
});

public static RenderLayer pswgParticle(Identifier texture, boolean affectsOutline)
{
return PSWG_PARTICLE.apply(texture, affectsOutline);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ protected void configure(RegistryWrapper.WrapperLookup wrapperLookup)
.add(Blocks.RED_MUSHROOM)
.add(Blocks.DEAD_BUSH)
.add(Blocks.SHORT_GRASS)
.add(Blocks.TALL_GRASS);
.add(Blocks.TALL_GRASS)
.add(Blocks.SNOW);

getOrCreateTagBuilder(Gadgets.DETONATES_GRENADE)
.add(Blocks.REDSTONE_BLOCK)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package dev.pswg.particles;

import dev.pswg.PswgGadgetsRenderLayers;
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.*;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.particle.SimpleParticleType;
import org.jetbrains.annotations.Nullable;

@Environment(value = EnvType.CLIENT)
public class NeuralGasParticle extends SpriteBillboardParticle
{
private final int variant;
final int NUM_VARIANTS = 7;

protected NeuralGasParticle(ClientWorld clientWorld, double x, double y, double z, double vX, double vY, double vZ, SpriteProvider spriteProvider)
{
super(clientWorld, x, y, z);
scale(16f);

setBoundingBoxSpacing(0.25f, 0.25f);
this.setAlpha(0.95f);
variant = random.nextInt(NUM_VARIANTS);
velocityX = random.nextFloat() / 10f * (random.nextBoolean() ? 1 : -1);
velocityZ = random.nextFloat() / 10f * (random.nextBoolean() ? 1 : -1);
this.setColor(1, 0.8f, 1);
}

@Override
public void render(VertexConsumer vertexConsumer, Camera camera, float tickDelta)
{
var texture = this.sprite.getAtlasId();
var mc = MinecraftClient.getInstance();
var v = mc.getBufferBuilders().getEffectVertexConsumers().getBuffer(PswgGadgetsRenderLayers.pswgParticle(texture, true));
super.render(v, camera, tickDelta);
}

@Override
public void tick()
{

prevPosX = x;
prevPosY = y;
prevPosZ = z;
age++;
if (alpha <= 0.0f)
{
markDead();
return;
}
if (age >= 100)
{
alpha -= 0.001f;
}
if (alpha <= 0.25f)
velocityY += 1 / 2000f;
velocityX *= 0.95;
velocityZ *= 0.95;
move(velocityX, velocityY, velocityZ);
}

@Override
public ParticleTextureSheet getType()
{
return ParticleTextureSheet.PARTICLE_SHEET_TRANSLUCENT;
}

@Environment(value = EnvType.CLIENT)
public static class Factory implements ParticleFactory<SimpleParticleType>
{
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)
{
NeuralGasParticle neuralGasParticle = new NeuralGasParticle(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider);
neuralGasParticle.setSprite(spriteProvider);
return neuralGasParticle;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected SmokeParticle(ClientWorld clientWorld, double x, double y, double z, d
setBoundingBoxSpacing(0.25f, 0.25f);
this.setAlpha(0.95f);
variant = random.nextInt(NUM_VARIANTS);
this.setColor(0.975f, 0.975f, 1);
}

@Override
Expand All @@ -47,7 +48,6 @@ public void tick()
velocityY += 0.00005;
}
move(velocityX, velocityY, velocityZ);
setColor(1, 0.8f, 1);
}

@Override
Expand All @@ -70,9 +70,9 @@ public Factory(SpriteProvider spriteProvider)
@Override
public Particle createParticle(SimpleParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ)
{
SmokeParticle explosionSmokeParticle = new SmokeParticle(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider);
explosionSmokeParticle.setSprite(spriteProvider);
return explosionSmokeParticle;
SmokeParticle smokeParticle = new SmokeParticle(world, x, y, z, velocityX, velocityY, velocityZ, spriteProvider);
smokeParticle.setSprite(spriteProvider);
return smokeParticle;
}
}
}
1 change: 1 addition & 0 deletions projects/pswg_gadgets/src/main/java/dev/pswg/Gadgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public static Identifier id(String path)
public static final SimpleParticleType FRAGMENTATION_GRENADE_SPARK_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_spark"), FabricParticleTypes.simple());
public static final SimpleParticleType FRAGMENTATION_GRENADE_WAVE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("fragmentation_grenade_wave"), FabricParticleTypes.simple());
public static final SimpleParticleType SMOKE_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("smoke"), FabricParticleTypes.simple());
public static final SimpleParticleType NEURAL_GAS_PARTICLE = Registry.register(Registries.PARTICLE_TYPE, id("neural_gas"), FabricParticleTypes.simple());

public static final SoundEvent ARM = registerSound(id("shared.arm"));
public static final SoundEvent DISARM = registerSound(id("shared.disarm"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.pswg.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;

public class NeuralGasEntity extends Entity
{

public NeuralGasEntity(EntityType<?> type, World world)
{
super(type, world);
}

@Override
protected void initDataTracker(DataTracker.Builder builder)
{

}

@Override
public boolean damage(ServerWorld world, DamageSource source, float amount)
{
return false;
}

@Override
protected void readCustomDataFromNbt(NbtCompound nbt)
{

}

@Override
protected void writeCustomDataToNbt(NbtCompound nbt)
{

}

@Override
public void tick()
{
super.tick();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.pswg.entity;

import dev.pswg.item.GrenadeItem;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import net.minecraft.world.World;

public class NeuralGasGrenadeEntity extends GrenadeEntity
{
public NeuralGasGrenadeEntity(EntityType<? extends ThrownEntity> entityType, World world)
{
super(entityType, world);
}

@Override
public GrenadeItem getItem()
{
return null;
}

@Override
public void explode()
{
super.explode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"textures": [
"minecraft:big_smoke_0",
"minecraft:big_smoke_1",
"minecraft:big_smoke_2",
"minecraft:big_smoke_3",
"minecraft:big_smoke_4",
"minecraft:big_smoke_5",
"minecraft:big_smoke_6"
]
}

0 comments on commit b6c5e4e

Please sign in to comment.