From 1a0fd8887d42c41a31ada9ac7ee90ad700859ca3 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 9 Dec 2016 21:36:43 +0100 Subject: [PATCH] Replace particles with laser renderers. Woop woop! --- .../mod/blocks/render/RenderEmpowerer.java | 17 ++++++ .../mod/misc/ParticleBeam.java | 55 +++++++++++++++++++ .../mod/misc/ParticleColored.java | 27 --------- .../mod/network/PacketHandler.java | 2 +- .../tile/TileEntityAtomicReconstructor.java | 2 +- .../mod/tile/TileEntityEmpowerer.java | 27 +++++++-- .../mod/tile/TileEntityLeafGenerator.java | 2 +- .../mod/tile/TileEntityMiner.java | 2 +- .../mod/tile/TileEntityPhantomPlacer.java | 4 -- .../mod/tile/TileEntityPhantomface.java | 6 -- .../actuallyadditions/mod/util/AssetUtil.java | 30 ++++------ 11 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleBeam.java delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleColored.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java index 5bcd1d33e..e0aee3683 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/render/RenderEmpowerer.java @@ -10,6 +10,8 @@ package de.ellpeck.actuallyadditions.mod.blocks.render; +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; import de.ellpeck.actuallyadditions.mod.tile.TileEntityEmpowerer; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil; @@ -20,6 +22,8 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.BlockPos; public class RenderEmpowerer extends TileEntitySpecialRenderer{ @@ -49,5 +53,18 @@ public class RenderEmpowerer extends TileEntitySpecialRenderer{ GlStateManager.popMatrix(); } + + int index = ((TileEntityEmpowerer)tile).recipeForRenderIndex; + if(index >= 0 && ActuallyAdditionsAPI.EMPOWERER_RECIPES.size() > index){ + EmpowererRecipe recipe = ActuallyAdditionsAPI.EMPOWERER_RECIPES.get(index); + if(recipe != null){ + for(int i = 0; i < EnumFacing.HORIZONTALS.length; i++){ + EnumFacing facing = EnumFacing.HORIZONTALS[i]; + BlockPos offset = tile.getPos().offset(facing, 3); + + AssetUtil.renderLaser(tile.getPos().getX()+0.5, tile.getPos().getY()+0.5, tile.getPos().getZ()+0.5, offset.getX()+0.5, offset.getY()+0.95, offset.getZ()+0.5, 80, 1F, 0.1F, recipe.particleColor); + } + } + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleBeam.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleBeam.java new file mode 100644 index 000000000..057b938c5 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleBeam.java @@ -0,0 +1,55 @@ +/* + * This file ("ParticleBeam.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.misc; + +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.client.particle.Particle; +import net.minecraft.client.renderer.VertexBuffer; +import net.minecraft.entity.Entity; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class ParticleBeam extends Particle{ + + private final double endX; + private final double endY; + private final double endZ; + private final float[] color; + private final double rotationTime; + private final float size; + private final float alpha; + + public ParticleBeam(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha){ + super(world, startX, startY, startZ); + this.endX = endX; + this.endY = endY; + this.endZ = endZ; + this.color = color; + this.rotationTime = rotationTime; + this.size = size; + this.particleMaxAge = maxAge; + this.alpha = alpha; + } + + @Override + public void renderParticle(VertexBuffer buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ){ + float ageRatio = (float)this.particleAge/(float)this.particleMaxAge; + float currAlpha = this.alpha-ageRatio*this.alpha; + AssetUtil.renderLaser(this.posX+0.5, this.posY+0.5, this.posZ+0.5, this.endX+0.5, this.endY+0.5, this.endZ+0.5, this.rotationTime, currAlpha, this.size, this.color); + } + + @Override + public int getFXLayer(){ + return 3; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleColored.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleColored.java deleted file mode 100644 index 4124171e9..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/ParticleColored.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file ("ParticleColored.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2016 Ellpeck - */ - -package de.ellpeck.actuallyadditions.mod.misc; - -import net.minecraft.client.particle.ParticleRedstone; -import net.minecraft.world.World; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class ParticleColored extends ParticleRedstone{ - - public ParticleColored(World world, double x, double y, double z, float size, float r, float g, float b, float ageMulti){ - super(world, x, y, z, size, r, g, b); - //To work around Reddust particles resetting the color to red if it's 0 (which is really stupid to be honest) - this.particleRed = ((float)(Math.random()*0.2)+0.8F)*r*((float)Math.random()*0.4F+0.6F); - this.particleMaxAge = (int)((8.0D/(Math.random()*0.8D+0.2D))*ageMulti); - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 6c581e611..d2afdff2c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -42,7 +42,7 @@ public final class PacketHandler{ @Override @SideOnly(Side.CLIENT) public void handleData(NBTTagCompound compound){ - AssetUtil.renderParticlesFromAToB(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), compound.getInteger("ParticleAmount"), compound.getFloat("ParticleSize"), new float[]{compound.getFloat("Color1"), compound.getFloat("Color2"), compound.getFloat("Color3")}, compound.getFloat("AgeMultiplier")); + AssetUtil.spawnLaserWithTimeClient(compound.getDouble("StartX"), compound.getDouble("StartY"), compound.getDouble("StartZ"), compound.getDouble("EndX"), compound.getDouble("EndY"), compound.getDouble("EndZ"), new float[]{compound.getFloat("Color1"), compound.getFloat("Color2"), compound.getFloat("Color3")}, compound.getInteger("MaxAge"), compound.getDouble("RotationTime"), compound.getFloat("Size"), compound.getFloat("Alpha")); } }; public static final IDataHandler TILE_ENTITY_HANDLER = new IDataHandler(){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 55011cff1..cf0b11ee8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -41,7 +41,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public static void shootLaser(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens){ world.playSound(null, startX, startY, startZ, SoundHandler.reconstructor, SoundCategory.BLOCKS, 0.35F, 1.0F); - AssetUtil.shootParticles(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 8, 2F, 1F); + AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java index 92a58832c..908626178 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityEmpowerer.java @@ -12,7 +12,6 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; -import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.item.ItemStack; @@ -29,7 +28,9 @@ import java.util.List; public class TileEntityEmpowerer extends TileEntityInventoryBase{ - private int processTime; + public int processTime; + public int recipeForRenderIndex; + private int lastRecipe; public TileEntityEmpowerer(){ super(1, "empowerer"); @@ -57,6 +58,7 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{ for(EmpowererRecipe recipe : recipes){ TileEntityDisplayStand[] modifierStands = this.getFittingModifiers(recipe, recipe.time); if(modifierStands != null){ //Meaning the display stands around match all the criteria + this.recipeForRenderIndex = ActuallyAdditionsAPI.EMPOWERER_RECIPES.indexOf(recipe); this.processTime++; boolean done = this.processTime >= recipe.time; @@ -67,27 +69,34 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{ if(done){ stand.slots.decrStackSize(0, 1); } - - AssetUtil.shootParticles(this.world, stand.getPos().getX(), stand.getPos().getY()+0.45F, stand.getPos().getZ(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), recipe.particleColor, 8, 0.5F, 0.45F); } if(this.processTime%5 == 0 && this.world instanceof WorldServer){ - ((WorldServer)this.world).spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 3, 0, 0, 0, 0.1D); + ((WorldServer)this.world).spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 2, 0, 0, 0, 0.1D); } if(done){ - ((WorldServer)this.world).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 300, 0, 0, 0, 0.25D); + ((WorldServer)this.world).spawnParticle(EnumParticleTypes.END_ROD, false, this.pos.getX()+0.5, this.pos.getY()+1.1, this.pos.getZ()+0.5, 100, 0, 0, 0, 0.25D); this.slots.setStackInSlot(0, recipe.output.copy()); this.markDirty(); this.processTime = 0; + this.recipeForRenderIndex = -1; } + + break; } } } else{ this.processTime = 0; + this.recipeForRenderIndex = -1; + } + + if(this.lastRecipe != this.recipeForRenderIndex){ + this.lastRecipe = this.recipeForRenderIndex; + this.sendUpdate(); } } } @@ -127,6 +136,9 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{ if(type == NBTType.SAVE_TILE){ compound.setInteger("ProcessTime", this.processTime); } + if(type == NBTType.SYNC){ + compound.setInteger("RenderIndex", this.recipeForRenderIndex); + } } @Override @@ -135,6 +147,9 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{ if(type == NBTType.SAVE_TILE){ this.processTime = compound.getInteger("ProcessTime"); } + if(type == NBTType.SYNC){ + this.recipeForRenderIndex = compound.getInteger("RenderIndex"); + } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index bc789992c..e21b4348b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -79,7 +79,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE this.storage.receiveEnergyInternal(ENERGY_PRODUCED, false); - AssetUtil.shootParticles(this.world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 1.0F, 1F); + AssetUtil.spawnLaserWithTimeServer(this.world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), new float[]{62F/255F, 163F/255F, 74F/255F}, 25, 0, 0.075F, 0.8F); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java index 39186baee..8f179058b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityMiner.java @@ -185,7 +185,7 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR } private void shootParticles(int endX, int endY, int endZ){ - AssetUtil.shootParticles(this.world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), endX, endY, endZ, new float[]{62F/255F, 163F/255F, 74F/255F}, 5, 1.0F, 1F); + AssetUtil.spawnLaserWithTimeServer(this.world, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), endX, endY, endZ, new float[]{65F/255F, 150F/255F, 2F/255F}, 10, 120, 0.1F, 0.8F); } private boolean isBlacklisted(Block block){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java index 76f161619..d81362282 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomPlacer.java @@ -169,10 +169,6 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements double d3 = (double)(this.world.rand.nextFloat()*1.0F*(float)i1); this.world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5); } - - if(this.ticksElapsed%80 == 0){ - AssetUtil.renderParticlesFromAToB(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.boundPosition.getX(), this.boundPosition.getY(), this.boundPosition.getZ(), 2, 0.35F, TileEntityPhantomface.COLORS, 3); - } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index 012ff397b..2cd410e32 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -15,7 +15,6 @@ import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; @@ -29,7 +28,6 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile{ public static final int RANGE = 16; - public static final float[] COLORS = new float[]{93F/255F, 43F/255F, 181F/255F}; public BlockPos boundPosition; public BlockPhantom.Type type; public int range; @@ -146,10 +144,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP double d3 = (double)(this.world.rand.nextFloat()*1.0F*(float)i1); this.world.spawnParticle(EnumParticleTypes.PORTAL, d0, d1, d2, d3, d4, d5); } - - if(this.ticksElapsed%80 == 0){ - AssetUtil.renderParticlesFromAToB(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.boundPosition.getX(), this.boundPosition.getY(), this.boundPosition.getZ(), 2, 0.35F, COLORS, 3); - } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java index 5409755dc..2ab71365e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/AssetUtil.java @@ -10,13 +10,14 @@ package de.ellpeck.actuallyadditions.mod.util; -import de.ellpeck.actuallyadditions.mod.misc.ParticleColored; +import de.ellpeck.actuallyadditions.mod.misc.ParticleBeam; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.particle.Particle; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager.DestFactor; import net.minecraft.client.renderer.GlStateManager.SourceFactor; @@ -171,7 +172,7 @@ public final class AssetUtil{ GlStateManager.popMatrix(); } - public static void shootParticles(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int particleAmount, float particleSize, float ageMultiplier){ + public static void spawnLaserWithTimeServer(World world, double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha){ if(!world.isRemote){ NBTTagCompound data = new NBTTagCompound(); data.setDouble("StartX", startX); @@ -183,32 +184,21 @@ public final class AssetUtil{ data.setFloat("Color1", color[0]); data.setFloat("Color2", color[1]); data.setFloat("Color3", color[2]); - data.setInteger("ParticleAmount", particleAmount); - data.setFloat("ParticleSize", particleSize); - data.setFloat("AgeMultiplier", ageMultiplier); + data.setDouble("RotationTime", rotationTime); + data.setFloat("Size", size); + data.setInteger("MaxAge", maxAge); + data.setFloat("Alpha", alpha); PacketHandler.theNetwork.sendToAllAround(new PacketServerToClient(data, PacketHandler.PARTICLE_HANDLER), new NetworkRegistry.TargetPoint(world.provider.getDimension(), startX, startY, startZ, 96)); } } @SideOnly(Side.CLIENT) - public static void renderParticlesFromAToB(double startX, double startY, double startZ, double endX, double endY, double endZ, int particleAmount, float particleSize, float[] color, float ageMultiplier){ + public static void spawnLaserWithTimeClient(double startX, double startY, double startZ, double endX, double endY, double endZ, float[] color, int maxAge, double rotationTime, float size, float alpha){ Minecraft mc = Minecraft.getMinecraft(); - int particleSetting = mc.gameSettings.particleSetting; if(mc.player.getDistance(startX, startY, startZ) <= 64 || mc.player.getDistance(endX, endY, endZ) <= 64){ - double difX = startX-endX; - double difY = startY-endY; - double difZ = startZ-endZ; - double distance = new Vec3d(startX, startY, startZ).distanceTo(new Vec3d(endX, endY, endZ)); - - for(int times = 0; times < Math.max(particleAmount/2, 1); times++){ - for(double i = 0; i <= 1; i += 1/(distance*particleAmount)){ - if(particleSetting == 0 || (particleSetting == 1 && mc.world.rand.nextFloat() >= 0.8F) || (particleSetting > 1 && mc.world.rand.nextFloat() >= 0.99F)){ - ParticleColored fx = new ParticleColored(mc.world, (difX*i)+endX+0.5, (difY*i)+endY+0.5, (difZ*i)+endZ+0.5, particleSize, color[0], color[1], color[2], ageMultiplier); - mc.effectRenderer.addEffect(fx); - } - } - } + Particle fx = new ParticleBeam(mc.world, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha); + mc.effectRenderer.addEffect(fx); } }