-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Neural gas particle and "pswg_particle" render layer
- Loading branch information
1 parent
e5b943b
commit b6c5e4e
Showing
9 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
projects/pswg_gadgets/src/client/java/dev/pswg/PswgGadgetsRenderLayers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
projects/pswg_gadgets/src/client/java/dev/pswg/particles/NeuralGasParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
projects/pswg_gadgets/src/main/java/dev/pswg/entity/NeuralGasEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
projects/pswg_gadgets/src/main/java/dev/pswg/entity/NeuralGasGrenadeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
projects/pswg_gadgets/src/main/resources/assets/pswg_gadgets/particles/neural_gas.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |