mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-14 04:09:09 +01:00
Replace particles with laser renderers
This commit is contained in:
parent
465ca21843
commit
063459ed93
11 changed files with 105 additions and 66 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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(){
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
@ -30,6 +29,8 @@ import java.util.List;
|
|||
public class TileEntityEmpowerer extends TileEntityInventoryBase{
|
||||
|
||||
private 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,32 @@ public class TileEntityEmpowerer extends TileEntityInventoryBase{
|
|||
if(done){
|
||||
stand.decrStackSize(0, 1);
|
||||
}
|
||||
|
||||
AssetUtil.shootParticles(this.worldObj, 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, 1F);
|
||||
}
|
||||
|
||||
if(this.processTime%5 == 0 && this.worldObj instanceof WorldServer){
|
||||
((WorldServer)this.worldObj).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.worldObj).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.worldObj).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.worldObj).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[0] = recipe.output.copy();
|
||||
this.markDirty();
|
||||
|
||||
this.processTime = 0;
|
||||
this.recipeForRenderIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
this.processTime = 0;
|
||||
this.recipeForRenderIndex = -1;
|
||||
}
|
||||
|
||||
if(this.lastRecipe != this.recipeForRenderIndex){
|
||||
this.lastRecipe = this.recipeForRenderIndex;
|
||||
this.sendUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +134,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 +145,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
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE
|
|||
|
||||
this.storage.receiveEnergy(ENERGY_PRODUCED, false);
|
||||
|
||||
AssetUtil.shootParticles(this.worldObj, 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.worldObj, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ public class TileEntityMiner extends TileEntityInventoryBase implements ICustomE
|
|||
}
|
||||
|
||||
private void shootParticles(int endX, int endY, int endZ){
|
||||
AssetUtil.shootParticles(this.worldObj, 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.worldObj, 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){
|
||||
|
|
|
@ -169,10 +169,6 @@ public class TileEntityPhantomPlacer extends TileEntityInventoryBase implements
|
|||
double d3 = (double)(this.worldObj.rand.nextFloat()*1.0F*(float)i1);
|
||||
this.worldObj.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
|
||||
|
|
|
@ -151,10 +151,6 @@ public class TileEntityPhantomface extends TileEntityInventoryBase implements IP
|
|||
double d3 = (double)(this.worldObj.rand.nextFloat()*1.0F*(float)i1);
|
||||
this.worldObj.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
|
||||
|
|
|
@ -10,12 +10,13 @@
|
|||
|
||||
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 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.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
|
@ -34,8 +35,6 @@ import net.minecraftforge.fml.relauncher.Side;
|
|||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class AssetUtil{
|
||||
|
||||
public static final ResourceLocation GUI_INVENTORY_LOCATION = getGuiLocation("guiInventory");
|
||||
|
@ -168,7 +167,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);
|
||||
|
@ -180,34 +179,24 @@ 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.thePlayer.getDistance(startX, startY, startZ) <= 64 || mc.thePlayer.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.theWorld.rand.nextFloat() >= 0.8F) || (particleSetting > 1 && mc.theWorld.rand.nextFloat() >= 0.98F)){
|
||||
ParticleColored fx = new ParticleColored(mc.theWorld, (difX*i)+endX+0.5, (difY*i)+endY+0.5, (difZ*i)+endZ+0.5, particleSize, color[0], color[1], color[2], ageMultiplier);
|
||||
Particle fx = new ParticleBeam(mc.theWorld, startX, startY, startZ, endX, endY, endZ, color, maxAge, rotationTime, size, alpha);
|
||||
mc.effectRenderer.addEffect(fx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Thanks to feldim2425 for this.
|
||||
//I can't do rendering code. Ever.
|
||||
|
|
Loading…
Reference in a new issue