Redo rendering of the molecular assembler and it's animation

This commit is contained in:
Sebastian Hartte
2020-06-18 17:14:53 +02:00
parent 10ab5d0d5a
commit 98d6740bb2
21 changed files with 338 additions and 561 deletions
@@ -42,7 +42,6 @@ import appeng.client.render.effects.*;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketAssemblerAnimation;
import appeng.core.sync.packets.PacketValueConfig;
import appeng.helpers.IMouseWheelItem;
import appeng.server.ServerHelper;
@@ -94,15 +93,9 @@ public class ClientHelper extends ServerHelper {
final double posZ, final Object o) {
if (AEConfig.instance().isEnableEffects()) {
switch (effect) {
case Assembler:
this.spawnAssembler(world, posX, posY, posZ, o);
return;
case Vibrant:
this.spawnVibrant(world, posX, posY, posZ);
return;
case Crafting:
this.spawnCrafting(world, posX, posY, posZ);
return;
case Energy:
this.spawnEnergy(world, posX, posY, posZ);
return;
@@ -183,18 +176,6 @@ public class ClientHelper extends ServerHelper {
// FIXME }
}
// FIXME: double check all of these particle spawns, also move any of these that
// are triggered as part of a packet to the vanilla way of spawning particles
// from the server directly
private void spawnAssembler(final World world, final double posX, final double posY, final double posZ,
final Object o) {
final PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o;
final AssemblerFX fx = new AssemblerFX(world, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate,
paa.is.asItemStackRepresentation());
Minecraft.getInstance().particles.addEffect(fx);
}
private void spawnVibrant(final World w, final double x, final double y, final double z) {
if (AppEng.proxy.shouldAddParticles(Platform.getRandom())) {
final double d0 = (Platform.getRandomFloat() - 0.5F) * 0.26D;
@@ -205,15 +186,6 @@ public class ClientHelper extends ServerHelper {
}
}
private void spawnCrafting(final World w, final double posX, final double posY, final double posZ) {
final float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
final float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
final float z = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
Minecraft.getInstance().particles.addParticle(CraftingFx.TYPE, posX + x, posY + y, posZ + z, -x * 0.2, -y * 0.2,
-z * 0.2);
}
private void spawnEnergy(final World w, final double posX, final double posY, final double posZ) {
final float x = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
final float y = (float) (((Platform.getRandomInt() % 100) * 0.01) - 0.5) * 0.7f;
+1 -1
View File
@@ -19,5 +19,5 @@
package appeng.client;
public enum EffectType {
Energy, Lightning, Vibrant, Crafting, Assembler, LightningArc
Energy, Lightning, Vibrant, LightningArc
}
@@ -1,230 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.client.render.effects;
import java.util.Locale;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.particle.IAnimatedSprite;
import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.IParticleRenderType;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.command.arguments.ItemInput;
import net.minecraft.command.arguments.ItemParser;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleType;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.EffectType;
import appeng.core.AppEng;
import appeng.entity.EntityFloatingItem;
import appeng.entity.ICanDie;
public class AssemblerFX extends Particle implements ICanDie {
public static final ParticleType<AssemblerParticleData> TYPE = new ParticleType<>(false,
new AssemblerParticleData.Deserializer());
static {
TYPE.setRegistryName(AppEng.MOD_ID, "assembler_fx");
}
private final EntityFloatingItem fi;
private final float speed;
private float time = 0;
public AssemblerFX(final World w, final double x, final double y, final double z, final double r, final double g,
final double b, final float speed, final ItemStack displayItem) {
super(w, x, y, z, r, g, b);
this.motionX = 0;
this.motionY = 0;
this.motionZ = 0;
this.speed = speed;
this.fi = new EntityFloatingItem(this, w, x, y, z, displayItem);
w.addEntity(this.fi);
this.maxAge = (int) Math.ceil(Math.max(1, 100.0f / speed)) + 2;
}
@Override
public boolean isDead() {
return this.isExpired;
}
@Override
public int getBrightnessForRender(final float par1) {
final int j1 = 13;
return j1 << 20 | j1 << 4;
}
@Override
public void tick() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.age++ >= this.maxAge) {
this.setExpired();
}
this.motionY -= 0.04D * this.particleGravity;
this.move(this.motionX, this.motionY, this.motionZ);
this.motionX *= 0.9800000190734863D;
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
if (this.isExpired) {
this.fi.remove();
} else {
final float lifeSpan = (float) this.age / (float) this.maxAge;
this.fi.setProgress(lifeSpan);
}
}
@Override
public IParticleRenderType getRenderType() {
return IParticleRenderType.NO_RENDER;
}
@Override
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
this.time += partialTicks;
if (this.time > 4.0) {
this.time -= 4.0;
// if ( AppEng.proxy.shouldAddParticles( r ) )
for (int x = 0; x < (int) Math.ceil(this.speed / 5); x++) {
AppEng.proxy.spawnEffect(EffectType.Crafting, this.world, this.posX, this.posY, this.posZ, null);
}
}
}
public static class AssemblerParticleData implements IParticleData {
private final float r;
private final float g;
private final float b;
private final float speed;
private final ItemStack itemStack;
public AssemblerParticleData(float r, float g, float b, float speed, ItemStack itemStack) {
this.r = r;
this.g = g;
this.b = b;
this.speed = speed;
this.itemStack = itemStack;
}
@Override
public ParticleType<?> getType() {
return TYPE;
}
@Override
public void write(PacketBuffer buffer) {
buffer.writeFloat(r);
buffer.writeFloat(g);
buffer.writeFloat(b);
buffer.writeFloat(speed);
buffer.writeItemStack(itemStack);
}
public static class Deserializer implements IDeserializer<AssemblerParticleData> {
@Override
public AssemblerParticleData deserialize(ParticleType<AssemblerParticleData> particleTypeIn,
StringReader reader) throws CommandSyntaxException {
reader.expect(' ');
float r = reader.readFloat();
reader.expect(' ');
float g = reader.readFloat();
reader.expect(' ');
float b = reader.readFloat();
reader.expect(' ');
float speed = reader.readFloat();
reader.expect(' ');
ItemParser itemparser = (new ItemParser(reader, false)).parse();
ItemStack itemstack = (new ItemInput(itemparser.getItem(), itemparser.getNbt())).createStack(1, false);
return new AssemblerParticleData(r, g, b, speed, itemstack);
}
@Override
public AssemblerParticleData read(ParticleType<AssemblerParticleData> particleTypeIn, PacketBuffer buffer) {
float r = buffer.readFloat();
float g = buffer.readFloat();
float b = buffer.readFloat();
float speed = buffer.readFloat();
ItemStack itemStack = buffer.readItemStack();
return new AssemblerParticleData(r, g, b, speed, itemStack);
}
}
@Override
public String getParameters() {
return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f ", Registry.PARTICLE_TYPE.getKey(this.getType()),
this.r, this.g, this.b, this.speed)
+ (new ItemInput(this.itemStack.getItem(), this.itemStack.getTag())).serialize();
}
public float getR() {
return r;
}
public float getG() {
return g;
}
public float getB() {
return b;
}
public float getSpeed() {
return speed;
}
public ItemStack getItemStack() {
return itemStack;
}
}
@OnlyIn(Dist.CLIENT)
public static class Factory implements IParticleFactory<AssemblerParticleData> {
public Factory(IAnimatedSprite spriteSet) {
}
public Particle makeParticle(AssemblerParticleData data, World world, double x, double y, double z,
double xSpeed, double ySpeed, double zSpeed) {
return new AssemblerFX(world, x, y, z, data.r, data.g, data.b, data.speed, data.itemStack);
}
}
}
@@ -18,31 +18,20 @@
package appeng.client.render.effects;
import appeng.core.AppEng;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.ActiveRenderInfo;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Vector3f;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.ItemParticleData;
import net.minecraft.particles.ParticleType;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import appeng.api.util.AEPartLocation;
import appeng.core.AppEng;
@OnlyIn(Dist.CLIENT)
public class CraftingFx extends BreakingParticle {
public class CraftingFx extends SpriteTexturedParticle {
public static final BasicParticleType TYPE = new BasicParticleType(false);
@@ -50,117 +39,99 @@ public class CraftingFx extends BreakingParticle {
TYPE.setRegistryName(AppEng.MOD_ID, "crafting_fx");
}
private final int startBlkX;
private final int startBlkY;
private final int startBlkZ;
// Offset relative to center of block, is the starting point of the particle movement
private final float offsetX;
private final float offsetY;
private final float offsetZ;
public CraftingFx(final World par1World, final double x, final double y, final double z,
final IAnimatedSprite sprite) {
super(par1World, x, y, z, new ItemStack(Items.DIAMOND));
super(par1World, x, y, z);
// Pick a random normal, offset it by 0.35 and use that as the particle origin
Vector3f off = new Vector3f(
rand.nextFloat() - 0.5f,
rand.nextFloat() - 0.5f,
rand.nextFloat() - 0.5f
);
off.normalize();
off.mul(0.35f);
offsetX = off.getX();
offsetY = off.getY();
offsetZ = off.getZ();
this.particleGravity = 0;
this.particleBlue = 1;
this.particleGreen = 0.9f;
this.particleRed = 1;
this.particleAlpha = 1.3f;
this.particleScale = 1.5f;
this.selectSpriteRandomly(sprite);
this.maxAge /= 1.2;
this.startBlkX = MathHelper.floor(this.posX);
this.startBlkY = MathHelper.floor(this.posY);
this.startBlkZ = MathHelper.floor(this.posZ);
this.canCollide = false; // we're INSIDE the block anyway
}
@Override
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
if (partialTicks < 0 || partialTicks > 1) {
return;
}
float f = (this.age + partialTicks) / (float) this.maxAge;
float offX = (float) (MathHelper.lerp(partialTicks, this.prevPosX, this.posX));
float offY = (float) (MathHelper.lerp(partialTicks, this.prevPosY, this.posY));
float offZ = (float) (MathHelper.lerp(partialTicks, this.prevPosZ, this.posZ));
float offX = (float) posX + MathHelper.lerp(f, offsetX, 0);
float offY = (float) posY + MathHelper.lerp(f, offsetY, 0);
float offZ = (float) posZ + MathHelper.lerp(f, offsetZ, 0);
float alpha = MathHelper.lerp(easeOutCirc(f), 1.3f, 0.1f);
float scale = MathHelper.lerp(easeOutCirc(f), 0.13f, 0.0f);
final int blkX = MathHelper.floor(offX);
final int blkY = MathHelper.floor(offY);
final int blkZ = MathHelper.floor(offZ);
// I believe this particle is same as breaking particle, but should not exit the
// original block it was
// spawned in (which is encased in glass)
if (blkX == this.startBlkX && blkY == this.startBlkY && blkZ == this.startBlkZ) {
Vec3d vec3d = renderInfo.getProjectedView();
offX -= vec3d.x;
offY -= vec3d.y;
offZ -= vec3d.z;
Vec3d vec3d = renderInfo.getProjectedView();
offX -= vec3d.x;
offY -= vec3d.y;
offZ -= vec3d.z;
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 scale = this.getScale(partialTicks);
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) };
for (int i = 0; i < 4; ++i) {
Vector3f vector3f = avector3f[i];
vector3f.transform(renderInfo.getRotation());
vector3f.mul(scale);
vector3f.add(offX, offY, offZ);
}
float minU = this.getMinU();
float maxU = this.getMaxU();
float minV = this.getMinV();
float maxV = this.getMaxV();
int j = this.getBrightnessForRender(partialTicks);
buffer.pos(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).tex(maxU, maxV)
.color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).tex(maxU, minV)
.color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).tex(minU, minV)
.color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).tex(minU, maxV)
.color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j)
.endVertex();
for (int i = 0; i < 4; ++i) {
Vector3f vector3f = avector3f[i];
vector3f.transform(renderInfo.getRotation());
vector3f.mul(scale);
vector3f.add(offX, offY, offZ);
}
float minU = this.getMinU();
float maxU = this.getMaxU();
float minV = this.getMinV();
float maxV = this.getMaxV();
int j = 15728880; // full brightness
buffer.pos(avector3f[0].getX(), avector3f[0].getY(), avector3f[0].getZ()).tex(maxU, maxV)
.color(this.particleRed, this.particleGreen, this.particleBlue, alpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[1].getX(), avector3f[1].getY(), avector3f[1].getZ()).tex(maxU, minV)
.color(this.particleRed, this.particleGreen, this.particleBlue, alpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[2].getX(), avector3f[2].getY(), avector3f[2].getZ()).tex(minU, minV)
.color(this.particleRed, this.particleGreen, this.particleBlue, alpha).lightmap(j)
.endVertex();
buffer.pos(avector3f[3].getX(), avector3f[3].getY(), avector3f[3].getZ()).tex(minU, maxV)
.color(this.particleRed, this.particleGreen, this.particleBlue, alpha).lightmap(j)
.endVertex();
}
public void fromItem(final AEPartLocation d) {
this.posX += 0.2 * d.xOffset;
this.posY += 0.2 * d.yOffset;
this.posZ += 0.2 * d.zOffset;
this.particleScale *= 0.8f;
// https://easings.net/#easeOutCirc
private static float easeOutCirc(float x) {
return (float) Math.sqrt(1 - Math.pow(x - 1, 2));
}
@Override
public IParticleRenderType getRenderType() {
return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
}
@Override
public void tick() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.age++ >= this.maxAge) {
this.setExpired();
}
this.motionY -= 0.04D * this.particleGravity;
this.move(this.motionX, this.motionY, this.motionZ);
this.motionX *= 0.9800000190734863D;
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
this.particleScale *= 0.51f;
this.particleAlpha *= 0.51f;
}
public void setMotionX(float motionX) {
this.motionX = motionX;
}
public void setMotionY(float motionY) {
this.motionY = motionY;
}
public void setMotionZ(float motionZ) {
this.motionZ = motionZ;
}
@OnlyIn(Dist.CLIENT)