Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update particle system #5163

Draft
wants to merge 1 commit into
base: 1.19.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
import com.github.alexthe666.iceandfire.client.ClientProxy;
import com.github.alexthe666.iceandfire.client.particle.IafParticleType;
import com.github.alexthe666.iceandfire.config.ConfigHolder;
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
import com.github.alexthe666.iceandfire.entity.IafVillagerRegistry;
Expand Down Expand Up @@ -102,6 +103,7 @@ public IceAndFire() {
IafContainerRegistry.CONTAINERS.register(modBus);
IafRecipeSerializers.SERIALIZERS.register(modBus);
IafProcessors.PROCESSORS.register(modBus);
IafParticleType.PARTICLE_TYPES.register(modBus);

IafVillagerRegistry.POI_TYPES.register(modBus);
IafVillagerRegistry.PROFESSIONS.register(modBus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public void spawnParticle(final EnumParticles name, double x, double y, double z
case Blood:
particle = new ParticleBlood(world, x, y, z);
break;
case If_Pixie:
particle = new ParticlePixieDust(world, x, y, z, (float) motX, (float) motY, (float) motZ);
break;
case Siren_Appearance:
particle = new ParticleSirenAppearance(world, x, y, z, (int) motX);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.alexthe666.iceandfire.client.particle;

import com.github.alexthe666.iceandfire.IceAndFire;
import net.minecraft.core.particles.ParticleType;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RegisterParticleProvidersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

@Mod.EventBusSubscriber(modid = IceAndFire.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class IafParticleType {
public static final DeferredRegister<ParticleType<?>> PARTICLE_TYPES = DeferredRegister.create(ForgeRegistries.PARTICLE_TYPES, IceAndFire.MODID);

public static final RegistryObject<SimpleParticleType> PIXIE_DUST = PARTICLE_TYPES.register("pixie_dust", () -> new SimpleParticleType(false));

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void registerFactories(RegisterParticleProvidersEvent event) {
event.register(IafParticleType.PIXIE_DUST.get(), ParticlePixieDust.Factory::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ public int getLightColor(float partialTick) {
return 240;
}

public int getFXLayer() {
return 3;
}

@Override
public @NotNull ParticleRenderType getRenderType() {
return ParticleRenderType.CUSTOM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,9 @@ public void render(@NotNull VertexConsumer buffer, Camera renderInfo, float part
return ParticleRenderType.CUSTOM;
}


@Override
public int getLightColor(float partialTick) {
return 240;
}

public int getFXLayer() {
return 3;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ public int getLightColor(float partialTick) {
return 240;
}

public int getFXLayer() {
return 3;
}

@Override
public @NotNull ParticleRenderType getRenderType() {
return ParticleRenderType.CUSTOM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public int getLightColor(float partialTick) {
return super.getLightColor(partialTick);
}

public void onUpdate() {
@Override
public void tick() {
this.xo = x;
this.yo = y;
this.zo = z;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,101 +1,47 @@
package com.github.alexthe666.iceandfire.client.particle;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.particle.TextureSheetParticle;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
import net.minecraft.client.particle.*;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.NotNull;

public class ParticlePixieDust extends TextureSheetParticle {
private static final ResourceLocation PIXIE_DUST = new ResourceLocation("iceandfire:textures/particles/pixie_dust.png");
float reddustParticleScale;

public ParticlePixieDust(ClientLevel worldIn, double xCoordIn, double yCoordIn, double zCoordIn, float p_i46349_8_, float p_i46349_9_, float p_i46349_10_) {
this(worldIn, xCoordIn, yCoordIn, zCoordIn, 1F, p_i46349_8_, p_i46349_9_, p_i46349_10_);
}

protected ParticlePixieDust(ClientLevel worldIn, double xCoordIn, double yCoordIn, double zCoordIn, float scale, float red, float green, float blue) {
protected ParticlePixieDust(ClientLevel worldIn, double xCoordIn, double yCoordIn, double zCoordIn, float scale, double red, double green, double blue) {
super(worldIn, xCoordIn, yCoordIn, zCoordIn, 0.0D, 0.0D, 0.0D);
this.xd *= 0.10000000149011612D;
this.yd *= 0.10000000149011612D;
this.zd *= 0.10000000149011612D;
float f = (float) Math.random() * 0.4F + 0.6F;
this.rCol = ((float) (Math.random() * 0.20000000298023224D) + 0.8F) * red * f;
this.gCol = ((float) (Math.random() * 0.20000000298023224D) + 0.8F) * green * f;
this.bCol = ((float) (Math.random() * 0.20000000298023224D) + 0.8F) * blue * f;
this.rCol = (float) (((float) (Math.random() * 0.20000000298023224D) + 0.8F) * red * f);
this.gCol = (float) (((float) (Math.random() * 0.20000000298023224D) + 0.8F) * green * f);
this.bCol = (float) (((float) (Math.random() * 0.20000000298023224D) + 0.8F) * blue * f);
this.quadSize *= scale;
this.reddustParticleScale = this.quadSize;

this.lifetime = (int) (8.0D / (Math.random() * 0.8D + 0.2D));
this.lifetime = (int) ((float) this.lifetime * scale);
}

@Override
public void render(@NotNull VertexConsumer buffer, Camera renderInfo, float partialTicks) {
Vec3 inerp = renderInfo.getPosition();
float scaley = ((float) this.age + partialTicks) / (float) this.lifetime * 32.0F;
scaley = Mth.clamp(scaley, 0.0F, 1.0F);
this.quadSize = this.reddustParticleScale * scaley;

float width = quadSize * 0.09F;
if (age > this.getLifetime()) {
this.remove();
}

Vec3 Vector3d = renderInfo.getPosition();
float f = (float) (Mth.lerp(partialTicks, this.xo, this.x) - Vector3d.x());
float f1 = (float) (Mth.lerp(partialTicks, this.yo, this.y) - Vector3d.y());
float f2 = (float) (Mth.lerp(partialTicks, this.zo, this.z) - Vector3d.z());
Quaternion quaternion;
if (this.roll == 0.0F) {
quaternion = renderInfo.rotation();
} else {
quaternion = new Quaternion(renderInfo.rotation());
float f3 = Mth.lerp(partialTicks, this.oRoll, this.roll);
quaternion.mul(Vector3f.ZP.rotation(f3));
}

// TODO :: 1.19.2 - This doesn't get utilized (the passed-in quaterion does not change)?
// Vector3f vector3f1 = new Vector3f(-1.0F, -1.0F, 0.0F);
// vector3f1.transform(quaternion);
Vector3f[] avector3f = 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 f4 = this.getQuadSize(partialTicks);

for (int i = 0; i < 4; ++i) {
Vector3f vector3f = avector3f[i];
vector3f.transform(quaternion);
vector3f.mul(f4);
vector3f.add(f, f1, f2);
@OnlyIn(Dist.CLIENT)
public record Factory(SpriteSet sprite) implements ParticleProvider<SimpleParticleType> {
@Override
public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double red, double green, double blue) {
ParticlePixieDust particle = new ParticlePixieDust(level, x, y, z, 1F, red, green, blue);
particle.pickSprite(this.sprite);
return particle;
}
float f7 = 0;
float f8 = 1;
float f5 = 0;
float f6 = 1;
RenderSystem.setShaderTexture(0, PIXIE_DUST);
int j = this.getLightColor(partialTicks);
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder vertexbuffer = tessellator.getBuilder();
vertexbuffer.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
vertexbuffer.vertex(avector3f[0].x(), avector3f[0].y(), avector3f[0].z()).uv(f8, f6).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
vertexbuffer.vertex(avector3f[1].x(), avector3f[1].y(), avector3f[1].z()).uv(f8, f5).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
vertexbuffer.vertex(avector3f[2].x(), avector3f[2].y(), avector3f[2].z()).uv(f7, f5).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
vertexbuffer.vertex(avector3f[3].x(), avector3f[3].y(), avector3f[3].z()).uv(f7, f6).color(this.rCol, this.gCol, this.bCol, this.alpha).uv2(j).endVertex();
Tesselator.getInstance().end();
}


@Override
public int getLightColor(float partialTick) {
return 240;
}

public void onUpdate() {
@Override
public void tick() {
this.xo = x;
this.yo = y;
this.zo = z;
Expand Down Expand Up @@ -123,6 +69,6 @@ public void onUpdate() {

@Override
public @NotNull ParticleRenderType getRenderType() {
return ParticleRenderType.CUSTOM;
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,9 @@ public void render(@NotNull VertexConsumer buffer, Camera renderInfo, float part

@Override
public int getLightColor(float partialTick) {
//If uncomment : BlockPos needs integers
// BlockPos blockpos = new BlockPos(this.x, this.y, this.z);
return 240;
}

public int getFXLayer() {
return 3;
}

@Override
public @NotNull ParticleRenderType getRenderType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public int getLightColor(float partialTick) {
return super.getLightColor(partialTick);
}

public int getFXLayer() {
return 3;
}

@Override
public @NotNull ParticleRenderType getRenderType() {
return ParticleRenderType.CUSTOM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.github.alexthe666.iceandfire.IceAndFire;
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
import com.github.alexthe666.iceandfire.client.particle.IafParticleType;
import com.github.alexthe666.iceandfire.datagen.tags.IafItemTags;
import com.github.alexthe666.iceandfire.entity.ai.*;
import com.github.alexthe666.iceandfire.entity.tile.TileEntityPixieHouse;
import com.github.alexthe666.iceandfire.enums.EnumParticles;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieHouse;
import com.github.alexthe666.iceandfire.misc.IafSoundRegistry;
import com.github.alexthe666.iceandfire.util.WorldUtil;
Expand Down Expand Up @@ -331,7 +331,7 @@ public void aiStep() {
this.setDeltaMovement(this.getDeltaMovement().add(0, 0.08, 0));
}
if (level.isClientSide) {
IceAndFire.PROXY.spawnParticle(EnumParticles.If_Pixie, this.getX() + (double) (this.random.nextFloat() * this.getBbWidth() * 2F) - (double) this.getBbWidth(), this.getY() + (double) (this.random.nextFloat() * this.getBbHeight()), this.getZ() + (double) (this.random.nextFloat() * this.getBbWidth() * 2F) - (double) this.getBbWidth(), PARTICLE_RGB[this.getColor()][0], PARTICLE_RGB[this.getColor()][1], PARTICLE_RGB[this.getColor()][2]);
level.addParticle(IafParticleType.PIXIE_DUST.get(), this.getX() + (double) (this.random.nextFloat() * this.getBbWidth() * 2F) - (double) this.getBbWidth(), this.getY() + (double) (this.random.nextFloat() * this.getBbHeight()), this.getZ() + (double) (this.random.nextFloat() * this.getBbWidth() * 2F) - (double) this.getBbWidth(), PARTICLE_RGB[this.getColor()][0], PARTICLE_RGB[this.getColor()][1], PARTICLE_RGB[this.getColor()][2]);
}
if (ticksUntilHouseAI > 0) {
ticksUntilHouseAI--;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.alexthe666.iceandfire.entity;

import com.github.alexthe666.iceandfire.IceAndFire;
import com.github.alexthe666.iceandfire.enums.EnumParticles;
import com.github.alexthe666.iceandfire.client.particle.IafParticleType;
import com.github.alexthe666.iceandfire.item.IafItemRegistry;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.network.protocol.Packet;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void tick() {
Entity shootingEntity = this.getOwner();
if (this.level.isClientSide) {
for (int i = 0; i < 5; ++i) {
IceAndFire.PROXY.spawnParticle(EnumParticles.If_Pixie, this.getX() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), this.getY() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), this.getZ() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), rgb[0], rgb[1], rgb[2]);
level.addParticle(IafParticleType.PIXIE_DUST.get(), this.getX() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), this.getY() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), this.getZ() + this.random.nextDouble() * 0.15F * (this.random.nextBoolean() ? -1 : 1), rgb[0], rgb[1], rgb[2]);
}
}
this.clearFire();
Expand Down Expand Up @@ -138,7 +137,7 @@ protected void onHit(@NotNull HitResult movingObject) {
}
if (this.level.isClientSide) {
for (int i = 0; i < 20; ++i) {
IceAndFire.PROXY.spawnParticle(EnumParticles.If_Pixie, this.getX() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), this.getY() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), this.getZ() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), rgb[0], rgb[1], rgb[2]);
level.addParticle(IafParticleType.PIXIE_DUST.get(), this.getX() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), this.getY() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), this.getZ() + this.random.nextDouble() * 1F * (this.random.nextBoolean() ? -1 : 1), rgb[0], rgb[1], rgb[2]);
}
}
if (shootingEntity == null || !(shootingEntity instanceof Player) || !((Player) shootingEntity).isCreative()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.alexthe666.iceandfire.entity.tile;

import com.github.alexthe666.iceandfire.IceAndFire;
import com.github.alexthe666.iceandfire.client.particle.IafParticleType;
import com.github.alexthe666.iceandfire.entity.EntityPixie;
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
import com.github.alexthe666.iceandfire.enums.EnumParticles;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieHouse;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieHouseModel;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieJar;
Expand Down Expand Up @@ -102,7 +102,7 @@ public void load(CompoundTag compound) {
public static void tick(Level level, BlockPos pos, BlockState state, TileEntityJar entityJar) {
entityJar.ticksExisted++;
if (level.isClientSide && entityJar.hasPixie) {
IceAndFire.PROXY.spawnParticle(EnumParticles.If_Pixie,
level.addParticle(IafParticleType.PIXIE_DUST.get(),
pos.getX() + 0.5F + (double) (entityJar.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH,
pos.getY() + (double) (entityJar.rand.nextFloat() * PARTICLE_HEIGHT),
pos.getZ() + 0.5F + (double) (entityJar.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH, EntityPixie.PARTICLE_RGB[entityJar.pixieType][0], EntityPixie.PARTICLE_RGB[entityJar.pixieType][1], EntityPixie.PARTICLE_RGB[entityJar.pixieType][2]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.github.alexthe666.iceandfire.IceAndFire;
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
import com.github.alexthe666.iceandfire.client.particle.IafParticleType;
import com.github.alexthe666.iceandfire.entity.EntityPixie;
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
import com.github.alexthe666.iceandfire.enums.EnumParticles;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieHouse;
import com.github.alexthe666.iceandfire.message.MessageUpdatePixieHouseModel;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -54,12 +54,12 @@ public static int getHouseTypeFromBlock(Block block) {

public static void tickClient(Level level, BlockPos pos, BlockState state, TileEntityPixieHouse entityPixieHouse) {
if (entityPixieHouse.hasPixie) {
IceAndFire.PROXY.spawnParticle(EnumParticles.If_Pixie,
pos.getX() + 0.5F + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH,
pos.getY() + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_HEIGHT),
pos.getZ() + 0.5F + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH,
EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][0], EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][1],
EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][2]);
level.addParticle(IafParticleType.PIXIE_DUST.get(),
pos.getX() + 0.5F + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH,
pos.getY() + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_HEIGHT),
pos.getZ() + 0.5F + (double) (entityPixieHouse.rand.nextFloat() * PARTICLE_WIDTH * 2F) - PARTICLE_WIDTH,
EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][0], EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][1],
EntityPixie.PARTICLE_RGB[entityPixieHouse.pixieType][2]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public enum EnumParticles {
Dread_Torch,
Dread_Portal,
Blood,
If_Pixie,
//If_Pixie,
Siren_Appearance,
Ghost_Appearance,
Siren_Music,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"textures": [
"iceandfire:pixie_dust"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.