Got tank item render work with fluids

This commit is contained in:
DarkGuardsman 2013-12-04 14:57:55 -05:00
parent 1394b4fccf
commit 23dc4f8073
5 changed files with 137 additions and 18 deletions

View file

@ -6,7 +6,8 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.fluid.client.render.BlockRenderHelper;
import dark.fluid.client.render.ItemRenderHelper;
import dark.fluid.client.render.ItemPipeRenderer;
import dark.fluid.client.render.ItemTankRenderer;
import dark.fluid.client.render.RenderConstructionPump;
import dark.fluid.client.render.RenderPipe;
import dark.fluid.client.render.RenderPump;
@ -43,8 +44,9 @@ public class ClientProxy extends CommonProxy
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityConstructionPump.class, new RenderConstructionPump());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTank.class, new RenderTank());
MinecraftForgeClient.registerItemRenderer(FMRecipeLoader.blockPipe.blockID, new ItemRenderHelper());
MinecraftForgeClient.registerItemRenderer(FMRecipeLoader.blockReleaseValve.blockID, new ItemRenderHelper());
MinecraftForgeClient.registerItemRenderer(FMRecipeLoader.blockPipe.blockID, new ItemPipeRenderer());
MinecraftForgeClient.registerItemRenderer(FMRecipeLoader.blockTank.blockID, new ItemTankRenderer());
MinecraftForgeClient.registerItemRenderer(FMRecipeLoader.blockReleaseValve.blockID, new ItemPipeRenderer());
RenderingRegistry.registerBlockHandler(new BlockRenderHelper());
}

View file

@ -30,7 +30,6 @@ public class BlockRenderHelper implements ISimpleBlockRenderingHandler
private ModelPump modelPump = new ModelPump();
private ModelGearRod modelRod = new ModelGearRod();
private ModelGenerator modelGen = new ModelGenerator();
private ModelTankSide tank = new ModelTankSide();
private ModelSink sink = new ModelSink();
private ModelConstructionPump conPump = new ModelConstructionPump();
@ -54,19 +53,7 @@ public class BlockRenderHelper implements ISimpleBlockRenderingHandler
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(FluidMech.instance.DOMAIN, ModPrefab.MODEL_DIRECTORY + "Sink.png"));
sink.render(0.0565F);
}
else if (FMRecipeLoader.blockTank != null && block.blockID == FMRecipeLoader.blockTank.blockID)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(FluidMech.instance.DOMAIN, metadata == 1 ? "textures/blocks/obsidian.png" : "textures/blocks/iron_block.png"));
GL11.glTranslatef(0.0F, -0.9F, 0.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.glRotatef(90f, 0f, 1f, 0f);
tank.render(0.0625F, false, false, false, false);
}
else if (FMRecipeLoader.blockRod != null && block.blockID == FMRecipeLoader.blockRod.blockID)
else if (FMRecipeLoader.blockRod != null && block.blockID == FMRecipeLoader.blockRod.blockID)
{
GL11.glTranslatef(0.0F, 1.5F, 0.0F);
GL11.glRotatef(180f, 0f, 0f, 1f);

View file

@ -17,7 +17,7 @@ import dark.fluid.common.FluidMech;
import dark.fluid.common.FluidPartsMaterial;
@SideOnly(Side.CLIENT)
public class ItemRenderHelper implements IItemRenderer
public class ItemPipeRenderer implements IItemRenderer
{
private ModelReleaseValve valve = new ModelReleaseValve();
private RenderPipe pipe = new RenderPipe();

View file

@ -0,0 +1,126 @@
package dark.fluid.client.render;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.fluid.client.model.ModelTankSide;
import dark.fluid.common.FMRecipeLoader;
import dark.fluid.common.FluidMech;
import dark.fluid.common.machines.BlockTank;
import dark.machines.CoreRecipeLoader;
import dark.machines.client.renders.RenderBlockFluid;
@SideOnly(Side.CLIENT)
public class ItemTankRenderer implements IItemRenderer
{
private ModelTankSide tank = new ModelTankSide();
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type)
{
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
{
return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
{
if (item.itemID == FMRecipeLoader.blockTank.blockID)
{
GL11.glPushMatrix();
GL11.glScalef(1.0F, 1.0F, 1.0F);
if (type == ItemRenderType.ENTITY)
{
GL11.glTranslatef(0F, 0.2F, 0F);
}
else if (type == ItemRenderType.EQUIPPED_FIRST_PERSON)
{
GL11.glTranslatef(0.4F, 0.6F, 0.2F);
}
else if (type == ItemRenderType.EQUIPPED)
{
GL11.glTranslatef(0.1F, 0.4F, 1.2F);
}
else
{
GL11.glTranslatef(0.7F, .4F, 0.7F);
}
FMLClientHandler.instance().getClient().renderEngine.bindTexture(new ResourceLocation(FluidMech.instance.DOMAIN, item.getItemDamage() == 1 ? "textures/blocks/obsidian.png" : "textures/blocks/iron_block.png"));
GL11.glTranslatef(0.0F, -0.9F, 0.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.glRotatef(90f, 0f, 1f, 0f);
tank.render(0.0625F, false, false, false, false);
GL11.glPopMatrix();
}
if (item.getTagCompound() != null && item.getTagCompound().hasKey("fluid"))
{
FluidStack liquid = FluidStack.loadFluidStackFromNBT(item.getTagCompound().getCompoundTag("fluid"));
if (liquid != null && liquid.amount > 100)
{
int[] displayList = RenderBlockFluid.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((RenderBlockFluid.getFluidSheet(liquid)));
int cap = BlockTank.tankVolume * FluidContainerRegistry.BUCKET_VOLUME;
if (liquid.getFluid().isGaseous())
{
cap = liquid.amount;
}
GL11.glCallList(displayList[(int) ((float) liquid.amount / (float) (cap) * (RenderBlockFluid.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
}

View file

@ -108,6 +108,10 @@ public class ItemBlockPipe extends ItemBlock
if (tile instanceof TileEntityFluidNetworkTile)
{
((TileEntityFluidNetworkTile) tile).setSubID(stack.getItemDamage());
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
{
((TileEntityFluidNetworkTile) tile).fillTankContent(0, FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag("fluid")), true);
}
}
return true;
}