Added BC fluid render and fixed them
This commit is contained in:
parent
5d12db00be
commit
eac9b1ee8c
3 changed files with 485 additions and 0 deletions
106
src/minecraft/dark/core/render/EntityBlock.java
Normal file
106
src/minecraft/dark/core/render/EntityBlock.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package dark.core.render;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class EntityBlock extends Entity
|
||||
{
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon texture;
|
||||
public float shadowSize = 0;
|
||||
public float rotationX = 0;
|
||||
public float rotationY = 0;
|
||||
public float rotationZ = 0;
|
||||
public double iSize, jSize, kSize;
|
||||
private int brightness = -1;
|
||||
|
||||
public EntityBlock(World world)
|
||||
{
|
||||
super(world);
|
||||
preventEntitySpawning = false;
|
||||
noClip = true;
|
||||
isImmuneToFire = true;
|
||||
}
|
||||
|
||||
public EntityBlock(World world, double xPos, double yPos, double zPos)
|
||||
{
|
||||
super(world);
|
||||
setPositionAndRotation(xPos, yPos, zPos, 0, 0);
|
||||
}
|
||||
|
||||
public EntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize)
|
||||
{
|
||||
this(world);
|
||||
this.iSize = iSize;
|
||||
this.jSize = jSize;
|
||||
this.kSize = kSize;
|
||||
setPositionAndRotation(i, j, k, 0, 0);
|
||||
this.motionX = 0.0;
|
||||
this.motionY = 0.0;
|
||||
this.motionZ = 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(double d, double d1, double d2)
|
||||
{
|
||||
super.setPosition(d, d1, d2);
|
||||
boundingBox.minX = posX;
|
||||
boundingBox.minY = posY;
|
||||
boundingBox.minZ = posZ;
|
||||
|
||||
boundingBox.maxX = posX + iSize;
|
||||
boundingBox.maxY = posY + jSize;
|
||||
boundingBox.maxZ = posZ + kSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveEntity(double d, double d1, double d2)
|
||||
{
|
||||
setPosition(posX + d, posY + d1, posZ + d2);
|
||||
}
|
||||
|
||||
public void setBrightness(int brightness)
|
||||
{
|
||||
this.brightness = brightness;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound data)
|
||||
{
|
||||
iSize = data.getDouble("iSize");
|
||||
jSize = data.getDouble("jSize");
|
||||
kSize = data.getDouble("kSize");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setDouble("iSize", iSize);
|
||||
data.setDouble("jSize", jSize);
|
||||
data.setDouble("kSize", kSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightnessForRender(float par1)
|
||||
{
|
||||
return brightness > 0 ? brightness : super.getBrightnessForRender(par1);
|
||||
}
|
||||
}
|
148
src/minecraft/dark/core/render/LiquidRenderer.java
Normal file
148
src/minecraft/dark/core/render/LiquidRenderer.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package dark.core.render;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import dark.core.render.RenderEntityBlock.BlockInterface;
|
||||
|
||||
/** @author CovertJaguar <railcraft.wikispaces.com> */
|
||||
public class LiquidRenderer
|
||||
{
|
||||
|
||||
private static Map<FluidStack, int[]> flowingRenderCache = new HashMap<FluidStack, int[]>();
|
||||
private static Map<FluidStack, int[]> stillRenderCache = new HashMap<FluidStack, int[]>();
|
||||
public static final int DISPLAY_STAGES = 100;
|
||||
private static final BlockInterface liquidBlock = new BlockInterface();
|
||||
|
||||
public static class LiquidTextureException extends RuntimeException
|
||||
{
|
||||
|
||||
private final FluidStack liquid;
|
||||
|
||||
public LiquidTextureException(FluidStack liquid)
|
||||
{
|
||||
super();
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage()
|
||||
{
|
||||
String liquidName = liquid.getFluid().getName();
|
||||
if (liquidName == null)
|
||||
{
|
||||
liquidName = String.format("ID: %d", liquid.getFluid().getBlockID());
|
||||
}
|
||||
return String.format("Liquid %s has no icon. Please contact the author of the mod the liquid came from.", liquidName);
|
||||
}
|
||||
}
|
||||
|
||||
public static Icon getLiquidTexture(FluidStack liquid)
|
||||
{
|
||||
if (liquid == null || liquid.getFluid() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Icon icon = liquid.getFluid().getIcon();
|
||||
if (icon == null)
|
||||
{
|
||||
throw new LiquidTextureException(liquid);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static String getLiquidSheet(Fluid liquid)
|
||||
{
|
||||
return "/terrain.png";
|
||||
}
|
||||
|
||||
public static int[] getLiquidDisplayLists(FluidStack liquid, World world, boolean flowing)
|
||||
{
|
||||
if (liquid == null || liquid.getFluid() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Fluid fluid = liquid.getFluid();
|
||||
|
||||
Map<FluidStack, int[]> cache = flowing ? flowingRenderCache : stillRenderCache;
|
||||
|
||||
int[] diplayLists = cache.get(liquid);
|
||||
if (diplayLists != null)
|
||||
{
|
||||
return diplayLists;
|
||||
}
|
||||
|
||||
diplayLists = new int[DISPLAY_STAGES];
|
||||
|
||||
if (fluid.getBlockID() < Block.blocksList.length && Block.blocksList[fluid.getBlockID()] != null)
|
||||
{
|
||||
liquidBlock.baseBlock = Block.blocksList[fluid.getBlockID()];
|
||||
if (!flowing)
|
||||
{
|
||||
liquidBlock.texture = getLiquidTexture(liquid);
|
||||
}
|
||||
}
|
||||
else if (Item.itemsList[fluid.getBlockID()] != null)
|
||||
{
|
||||
liquidBlock.baseBlock = Block.waterStill;
|
||||
liquidBlock.texture = getLiquidTexture(liquid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
cache.put(liquid, diplayLists);
|
||||
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
|
||||
int color = fluid.getColor();
|
||||
float c1 = (float) (color >> 16 & 255) / 255.0F;
|
||||
float c2 = (float) (color >> 8 & 255) / 255.0F;
|
||||
float c3 = (float) (color & 255) / 255.0F;
|
||||
GL11.glColor4f(c1, c2, c3, 1);
|
||||
for (int s = 0; s < DISPLAY_STAGES; ++s)
|
||||
{
|
||||
diplayLists[s] = GLAllocation.generateDisplayLists(1);
|
||||
GL11.glNewList(diplayLists[s], 4864 /*GL_COMPILE*/);
|
||||
|
||||
liquidBlock.minX = 0.01f;
|
||||
liquidBlock.minY = 0;
|
||||
liquidBlock.minZ = 0.01f;
|
||||
|
||||
liquidBlock.maxX = 0.99f;
|
||||
liquidBlock.maxY = (float) s / (float) DISPLAY_STAGES;
|
||||
liquidBlock.maxZ = 0.99f;
|
||||
|
||||
RenderEntityBlock.renderBlock(liquidBlock, world, 0, 0, 0, false, true);
|
||||
|
||||
GL11.glEndList();
|
||||
}
|
||||
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
|
||||
return diplayLists;
|
||||
}
|
||||
}
|
231
src/minecraft/dark/core/render/RenderEntityBlock.java
Normal file
231
src/minecraft/dark/core/render/RenderEntityBlock.java
Normal file
|
@ -0,0 +1,231 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package dark.core.render;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.resources.ResourceLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class RenderEntityBlock extends Render
|
||||
{
|
||||
|
||||
private static RenderBlocks renderBlocks = new RenderBlocks();
|
||||
private static final ResourceLocation field_110782_f = new ResourceLocation("textures/entity/boat.png");
|
||||
|
||||
public static class BlockInterface
|
||||
{
|
||||
|
||||
public double minX;
|
||||
public double minY;
|
||||
public double minZ;
|
||||
public double maxX;
|
||||
public double maxY;
|
||||
public double maxZ;
|
||||
|
||||
public Block baseBlock = Block.sand;
|
||||
|
||||
public Icon texture = null;
|
||||
|
||||
public Icon getBlockTextureFromSide(int i)
|
||||
{
|
||||
if (texture == null)
|
||||
return baseBlock.getBlockTextureFromSide(i);
|
||||
else
|
||||
return texture;
|
||||
}
|
||||
|
||||
public float getBlockBrightness(IBlockAccess iblockaccess, int i, int j, int k)
|
||||
{
|
||||
return baseBlock.getBlockBrightness(iblockaccess, i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
public RenderEntityBlock()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doRender(Entity entity, double i, double j, double k, float f, float f1)
|
||||
{
|
||||
doRenderBlock((EntityBlock) entity, i, j, k);
|
||||
}
|
||||
|
||||
public void doRenderBlock(EntityBlock entity, double i, double j, double k)
|
||||
{
|
||||
if (entity.isDead)
|
||||
return;
|
||||
|
||||
shadowSize = entity.shadowSize;
|
||||
World world = entity.worldObj;
|
||||
BlockInterface util = new BlockInterface();
|
||||
util.texture = entity.texture;
|
||||
|
||||
ResourceLocation name = new ResourceLocation("/terrain.png");
|
||||
func_110776_a(name);
|
||||
|
||||
for (int iBase = 0; iBase < entity.iSize; ++iBase)
|
||||
{
|
||||
for (int jBase = 0; jBase < entity.jSize; ++jBase)
|
||||
{
|
||||
for (int kBase = 0; kBase < entity.kSize; ++kBase)
|
||||
{
|
||||
|
||||
util.minX = 0;
|
||||
util.minY = 0;
|
||||
util.minZ = 0;
|
||||
|
||||
double remainX = entity.iSize - iBase;
|
||||
double remainY = entity.jSize - jBase;
|
||||
double remainZ = entity.kSize - kBase;
|
||||
|
||||
util.maxX = (remainX > 1.0 ? 1.0 : remainX);
|
||||
util.maxY = (remainY > 1.0 ? 1.0 : remainY);
|
||||
util.maxZ = (remainZ > 1.0 ? 1.0 : remainZ);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef((float) i, (float) j, (float) k);
|
||||
GL11.glRotatef(entity.rotationX, 1, 0, 0);
|
||||
GL11.glRotatef(entity.rotationY, 0, 1, 0);
|
||||
GL11.glRotatef(entity.rotationZ, 0, 0, 1);
|
||||
GL11.glTranslatef(iBase, jBase, kBase);
|
||||
|
||||
int lightX, lightY, lightZ;
|
||||
|
||||
lightX = (int) (Math.floor(entity.posX) + iBase);
|
||||
lightY = (int) (Math.floor(entity.posY) + jBase);
|
||||
lightZ = (int) (Math.floor(entity.posZ) + kBase);
|
||||
|
||||
GL11.glDisable(2896 /* GL_LIGHTING */);
|
||||
renderBlock(util, world, lightX, lightY, lightZ, false, true);
|
||||
GL11.glEnable(2896 /* GL_LIGHTING */);
|
||||
GL11.glPopMatrix();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderBlock(BlockInterface block, IBlockAccess blockAccess, int i, int j, int k, boolean doLight, boolean doTessellating)
|
||||
{
|
||||
float f = 0.5F;
|
||||
float f1 = 1.0F;
|
||||
float f2 = 0.8F;
|
||||
float f3 = 0.6F;
|
||||
|
||||
renderBlocks.renderMaxX = block.maxX;
|
||||
renderBlocks.renderMinX = block.minX;
|
||||
renderBlocks.renderMaxY = block.maxY;
|
||||
renderBlocks.renderMinY = block.minY;
|
||||
renderBlocks.renderMaxZ = block.maxZ;
|
||||
renderBlocks.renderMinZ = block.minZ;
|
||||
renderBlocks.enableAO = false;
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
if (doTessellating)
|
||||
{
|
||||
tessellator.startDrawingQuads();
|
||||
}
|
||||
|
||||
float f4 = 0, f5 = 0;
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f4 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f * f5, f * f5, f * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceYNeg(null, 0, 0, 0, block.getBlockTextureFromSide(0));
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f1 * f5, f1 * f5, f1 * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceYPos(null, 0, 0, 0, block.getBlockTextureFromSide(1));
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceZNeg(null, 0, 0, 0, block.getBlockTextureFromSide(2));
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f2 * f5, f2 * f5, f2 * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceZPos(null, 0, 0, 0, block.getBlockTextureFromSide(3));
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceXNeg(null, 0, 0, 0, block.getBlockTextureFromSide(4));
|
||||
|
||||
if (doLight)
|
||||
{
|
||||
f5 = block.getBlockBrightness(blockAccess, i, j, k);
|
||||
if (f5 < f4)
|
||||
{
|
||||
f5 = f4;
|
||||
}
|
||||
tessellator.setColorOpaque_F(f3 * f5, f3 * f5, f3 * f5);
|
||||
}
|
||||
|
||||
renderBlocks.renderFaceXPos(null, 0, 0, 0, block.getBlockTextureFromSide(5));
|
||||
|
||||
if (doTessellating)
|
||||
{
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceLocation func_110775_a(Entity par1Entity)
|
||||
{
|
||||
return field_110782_f;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue