Some work on new tank renderer

This commit is contained in:
Calclavia 2014-01-13 19:56:22 +08:00
parent 6d38db4d68
commit 3048d94f7a
5 changed files with 228 additions and 250 deletions

View file

@ -25,6 +25,6 @@ public class ClientProxy extends CommonProxy
MinecraftForgeClient.registerItemRenderer(Mechanical.blockTank.blockID, new ItemTankRenderer()); MinecraftForgeClient.registerItemRenderer(Mechanical.blockTank.blockID, new ItemTankRenderer());
MinecraftForgeClient.registerItemRenderer(Mechanical.blockPipe.blockID, new ItemPipeRenderer()); MinecraftForgeClient.registerItemRenderer(Mechanical.blockPipe.blockID, new ItemPipeRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TilePipe.class, new RenderPipe()); ClientRegistry.bindTileEntitySpecialRenderer(TilePipe.class, new RenderPipe());
ClientRegistry.bindTileEntitySpecialRenderer(TileTank.class, new RenderTank()); ClientRegistry.bindTileEntitySpecialRenderer(TileTank.class, RenderTank.INSTANCE);
} }
} }

View file

@ -23,8 +23,6 @@ import cpw.mods.fml.relauncher.SideOnly;
public class BlockTank extends BlockFluidNetwork public class BlockTank extends BlockFluidNetwork
{ {
public static int tankVolume = 16;
public BlockTank() public BlockTank()
{ {
super("tank"); super("tank");
@ -39,9 +37,17 @@ public class BlockTank extends BlockFluidNetwork
} }
@Override @Override
public int getRenderBlockPass() @SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{ {
return 1; return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return MechanicalBlockRenderingHandler.ID;
} }
@Override @Override
@ -51,20 +57,6 @@ public class BlockTank extends BlockFluidNetwork
return checkBlockID == this.blockID ? false : super.shouldSideBeRendered(blockAccess, x, y, z, side); return checkBlockID == this.blockID ? false : super.shouldSideBeRendered(blockAccess, x, y, z, side);
} }
@Override
@SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return 0;
}
@Override @Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ)
{ {

View file

@ -1,17 +1,13 @@
package resonantinduction.mechanical.fluid.tank; package resonantinduction.mechanical.fluid.tank;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer; import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference; import resonantinduction.core.Reference;
import resonantinduction.core.render.RenderFluidHelper;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.old.client.model.ModelTankSide; import resonantinduction.old.client.model.ModelTankSide;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -21,6 +17,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemTankRenderer implements IItemRenderer public class ItemTankRenderer implements IItemRenderer
{ {
private ModelTankSide tank = new ModelTankSide(); private ModelTankSide tank = new ModelTankSide();
private final TileTank tileTank = new TileTank();
@Override @Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) public boolean handleRenderType(ItemStack item, ItemRenderType type)
@ -36,8 +33,6 @@ public class ItemTankRenderer implements IItemRenderer
@Override @Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
if (item.itemID == Mechanical.blockTank.blockID)
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glScalef(1.0F, 1.0F, 1.0F); GL11.glScalef(1.0F, 1.0F, 1.0F);
@ -60,65 +55,13 @@ public class ItemTankRenderer implements IItemRenderer
} }
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Reference.DOMAIN, item.getItemDamage() == 1 ? "textures/blocks/obsidian.png" : "textures/blocks/iron_block.png")); FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(Reference.DOMAIN, item.getItemDamage() == 1 ? "textures/blocks/obsidian.png" : "textures/blocks/iron_block.png"));
GL11.glTranslatef(0.0F, -0.9F, 0.0F); FluidStack fluid = null;
tank.render(0.0625F, false, false, false, false);
GL11.glRotatef(90f, 0f, 1f, 0f);
tank.render(0.0625F, false, false, false, false);
GL11.glRotatef(90f, 0f, 1f, 0f);
tank.render(0.0625F, false, false, false, false);
GL11.glRotatef(90f, 0f, 1f, 0f);
tank.render(0.0625F, false, false, false, false);
GL11.glPopMatrix();
}
if (item.getTagCompound() != null && item.getTagCompound().hasKey("fluid")) if (item.getTagCompound() != null && item.getTagCompound().hasKey("fluid"))
{ {
FluidStack liquid = FluidStack.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("fluid")); fluid = FluidStack.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("fluid"));
if (liquid != null && liquid.amount > 100)
{
int[] displayList = RenderFluidHelper.getFluidDisplayLists(liquid, Minecraft.getMinecraft().theWorld, false);
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.glScalef(0.80F, 0.9F, 0.80F);
if (type == ItemRenderType.ENTITY)
{
GL11.glTranslatef(-.5F, -0.2F, -.5F);
}
else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON)
{
GL11.glTranslatef(-0.1F, 0.2F, -.3F);
}
else if (type == ItemRenderType.EQUIPPED)
{
GL11.glScalef(0.9F, 0.9F, 0.9F);
GL11.glTranslatef(-0.4F, 0.1F, 0.9F);
}
else
{
GL11.glScalef(0.80F, 0.9F, 0.80F);
GL11.glTranslatef(0.5F, .2F, 0.5F);
} }
FMLClientHandler.instance().getClient().renderEngine.bindTexture((RenderFluidHelper.getFluidSheet(liquid))); RenderTank.INSTANCE.renderTank(tileTank, 0, 0, 0, fluid);
int cap = BlockTank.tankVolume * FluidContainerRegistry.BUCKET_VOLUME;
if (liquid.getFluid().isGaseous())
{
cap = liquid.amount;
}
GL11.glCallList(displayList[(int) Math.min(((float) liquid.amount / (float) (cap) * (RenderFluidHelper.DISPLAY_STAGES - 1)), displayList.length - 1)]);
GL11.glPopAttrib();
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
}
}
} }

View file

@ -4,12 +4,15 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.core.render.RenderFluidHelper; import resonantinduction.core.render.RenderFluidHelper;
import resonantinduction.mechanical.Mechanical;
import resonantinduction.old.client.model.ModelTankSide; import resonantinduction.old.client.model.ModelTankSide;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import dark.lib.helpers.ColorCode; import dark.lib.helpers.ColorCode;
@ -17,25 +20,120 @@ import dark.lib.helpers.ColorCode;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class RenderTank extends TileEntitySpecialRenderer public class RenderTank extends TileEntitySpecialRenderer
{ {
private ModelTankSide model; public static final RenderTank INSTANCE = new RenderTank();
public final ModelTankSide model = new ModelTankSide();
public RenderTank()
{
model = new ModelTankSide();
}
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8) public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{ {
FluidStack liquid = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getFluid(): null; this.renderTank(tileEntity, x, y, z, tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getFluid() : null);
this.renderTank(tileEntity, x, y, z, 0, liquid);
} }
public void renderTank(TileEntity tileEntity, double x, double y, double z, int meta, FluidStack liquid) public void renderTank(TileEntity tileEntity, double x, double y, double z, FluidStack fluid)
{ {
if (liquid != null && liquid.amount > 100) byte renderSides = 0;
if (tileEntity instanceof TileTank)
{ {
int[] displayList = RenderFluidHelper.getFluidDisplayLists(liquid, tileEntity.worldObj, false); renderSides = ((TileTank) tileEntity).renderSides;
boolean down = TileTank.canRenderSide(renderSides, ForgeDirection.UP);
boolean up = TileTank.canRenderSide(renderSides, ForgeDirection.DOWN);
boolean north = TileTank.canRenderSide(renderSides, ForgeDirection.NORTH);
boolean south = TileTank.canRenderSide(renderSides, ForgeDirection.SOUTH);
boolean east = TileTank.canRenderSide(renderSides, ForgeDirection.EAST);
boolean west = TileTank.canRenderSide(renderSides, ForgeDirection.WEST);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
GL11.glPushMatrix();
if (!east)
{
if (!north)
{
// north east
RenderUtility.renderCube(0.475, -0.501, -0.501, 0.501, 0.501, -0.475, Mechanical.blockTank, null);
}
if (!south)
{
// south east
RenderUtility.renderCube(0.475, -0.501, 0.475, 0.501, 0.501, 0.501, Mechanical.blockTank, null);
}
if (!down)
{
// bottom east
RenderUtility.renderCube(0.475, -0.501, -0.501, 0.501, -0.475, 0.501, Mechanical.blockTank, null);
}
if (!up)
{
// top east
RenderUtility.renderCube(0.475, 0.475, -0.501, 0.501, 0.501, 0.501, Mechanical.blockTank, null);
}
}
if (!west)
{
if (!north)
{
// north west
RenderUtility.renderCube(-0.501, -0.501, -0.501, -0.475, 0.501, -0.475, Mechanical.blockTank, null);
}
if (!south)
{
// south west
RenderUtility.renderCube(-0.501, -0.501, 0.475, -0.475, 0.501, 0.501, Mechanical.blockTank, null);
}
if (!down)
{
// bottom west
RenderUtility.renderCube(-0.501, -0.501, -0.501, -0.475, -0.475, 0.501, Mechanical.blockTank, null);
}
if (!up)
{
// top west
RenderUtility.renderCube(-0.501, 0.475, -0.501, -0.475, 0.501, 0.501, Mechanical.blockTank, null);
}
}
if (!north)
{
if (!up)
{
// top north
RenderUtility.renderCube(-0.501, 0.475, -0.501, 0.501, 0.501, -0.475, Mechanical.blockTank, null);
}
if (!down)
{
// bottom north
RenderUtility.renderCube(-0.501, -0.501, -0.501, 0.501, -0.475, -0.475, Mechanical.blockTank, null);
}
}
if (!south)
{
if (!up)
{
// top south
RenderUtility.renderCube(-0.501, 0.475, 0.475, 0.501, 0.501, 0.501, Mechanical.blockTank, null);
}
if (!down)
{
// bottom south
RenderUtility.renderCube(-0.501, -0.501, 0.475, 0.501, -0.475, 0.501, Mechanical.blockTank, null);
}
}
GL11.glPopMatrix();
GL11.glPopMatrix();
//TODO: Remove
fluid = new FluidStack(FluidRegistry.WATER, 8000);
if (fluid != null && fluid.amount > 100)
{
int[] displayList = RenderFluidHelper.getFluidDisplayLists(fluid, tileEntity.worldObj, false);
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
@ -43,72 +141,15 @@ public class RenderTank extends TileEntitySpecialRenderer
GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
bindTexture(RenderFluidHelper.getFluidSheet(fluid));
bindTexture(RenderFluidHelper.getFluidSheet(liquid)); // Prevent Z-fighting
GL11.glTranslatef((float) x, (float) y + 0.001f, (float) z);
GL11.glTranslatef((float) x, (float) y, (float) z); int cap = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getCapacity() : fluid.amount;
GL11.glScalef(1.01F, 1.01F, 1.01F); GL11.glCallList(displayList[(int) ((float) fluid.amount / (float) (cap) * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
int cap = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getCapacity() : liquid.amount;
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (cap) * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib(); GL11.glPopAttrib();
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
/*
byte renderSides = 0;
if (tileEntity instanceof TileTank)
{
renderSides = ((TileTank) tileEntity).renderSides;
} }
boolean bot = TileTank.canRenderSide(renderSides, ForgeDirection.UP);
boolean top = TileTank.canRenderSide(renderSides, ForgeDirection.DOWN);
boolean north = TileTank.canRenderSide(renderSides, ForgeDirection.NORTH);
boolean south = TileTank.canRenderSide(renderSides, ForgeDirection.SOUTH);
boolean east = TileTank.canRenderSide(renderSides, ForgeDirection.EAST);
boolean west = TileTank.canRenderSide(renderSides, ForgeDirection.WEST);
for (int i = 0; i < 4; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i + 2);
if (!TileTank.canRenderSide(renderSides, dir.getOpposite()))
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
boolean left = false;
boolean right = false;
switch (dir)
{
case NORTH:
GL11.glRotatef(180f, 0f, 1f, 0f);
left = west;
right = east;
break;
case SOUTH:
GL11.glRotatef(0f, 0f, 1f, 0f);
left = east;
right = west;
break;
case WEST:
GL11.glRotatef(90f, 0f, 1f, 0f);
left = south;
right = north;
break;
case EAST:
GL11.glRotatef(270f, 0f, 1f, 0f);
left = north;
right = south;
break;
}
bindTexture(this.getTexture(tileEntity.getBlockType().blockID, tileEntity.getBlockMetadata()));
model.render(0.0625F, left, right, top, bot);
GL11.glPopMatrix();
}
}*/
} }
public ResourceLocation getTexture(int block, int meta) public ResourceLocation getTexture(int block, int meta)

View file

@ -8,9 +8,11 @@ import resonantinduction.mechanical.fluid.prefab.TileFluidNetwork;
public class TileTank extends TileFluidNetwork public class TileTank extends TileFluidNetwork
{ {
public static final int VOLUME = 16;
public TileTank() public TileTank()
{ {
super(BlockTank.tankVolume); super(VOLUME);
} }
@Override @Override