Replace particles with laser renderers. Woop woop!

This commit is contained in:
Ellpeck 2016-12-09 21:36:43 +01:00
parent 0630601b9d
commit 1a0fd8887d
11 changed files with 107 additions and 67 deletions

View file

@ -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);
}
}
}
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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(){

View file

@ -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

View file

@ -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

View file

@ -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);
}
}
}

View file

@ -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){

View file

@ -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

View file

@ -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

View file

@ -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);
}
}