Fixed tank item rendering

This commit is contained in:
Calclavia 2014-06-20 22:48:44 -07:00
parent 91f402b18f
commit ffa9be03d5
3 changed files with 232 additions and 185 deletions

View file

@ -1,9 +1,13 @@
package resonantinduction.archaic; package resonantinduction.archaic;
import resonant.lib.render.item.GlobalItemRenderer;
import resonantinduction.archaic.fluid.tank.TileTank;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
@Override @Override
public void preInit() public void preInit()
{ {
GlobalItemRenderer.register(Archaic.blockTank.blockID, TileTank.ItemRenderer.instance);
} }
} }

View file

@ -9,18 +9,17 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem; import net.minecraftforge.fluids.IFluidContainerItem;
import resonant.lib.utility.LanguageUtility; import resonant.lib.utility.LanguageUtility;
import resonantinduction.archaic.Archaic;
import resonantinduction.core.grid.fluid.TileFluidDistribution; import resonantinduction.core.grid.fluid.TileFluidDistribution;
import universalelectricity.api.energy.UnitDisplay; import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit; import universalelectricity.api.energy.UnitDisplay.Unit;
import universalelectricity.api.energy.UnitDisplay.UnitPrefix; import universalelectricity.api.energy.UnitDisplay.UnitPrefix;
import universalelectricity.api.vector.Vector3;
/** @author Darkguardsman */ /**
* @author Darkguardsman
*/
public class ItemBlockTank extends ItemBlock implements IFluidContainerItem public class ItemBlockTank extends ItemBlock implements IFluidContainerItem
{ {
public ItemBlockTank(int id) public ItemBlockTank(int id)
@ -38,11 +37,11 @@ public class ItemBlockTank extends ItemBlock implements IFluidContainerItem
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
{ {
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid")) if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid"))
{ {
FluidStack fluid = getFluid(stack); FluidStack fluid = getFluid(itemStack);
if (fluid != null) if (fluid != null)
{ {

View file

@ -18,6 +18,7 @@ import net.minecraftforge.fluids.FluidTank;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonant.api.IRemovable.ISneakPickup; import resonant.api.IRemovable.ISneakPickup;
import resonant.api.items.ISimpleItemRenderer;
import resonant.lib.content.module.TileBlock.IComparatorInputOverride; import resonant.lib.content.module.TileBlock.IComparatorInputOverride;
import resonant.lib.content.module.TileRender; import resonant.lib.content.module.TileRender;
import resonant.lib.render.FluidRenderUtility; import resonant.lib.render.FluidRenderUtility;
@ -154,9 +155,9 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity(); double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST); double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
double yNorthEast = percentageFilled;//FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST); double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
double ySouthWest = percentageFilled;//FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST); double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST);
double yNorthWest = percentageFilled;//FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST); double yNorthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST);
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest); FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest);
} }
else else
@ -198,30 +199,73 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
renderTank(TileTank.this, position.x, position.y, position.z, getInternalTank().getFluid()); renderTank(TileTank.this, position.x, position.y, position.z, getInternalTank().getFluid());
return false; return false;
} }
};
}
@Override public static class ItemRenderer implements ISimpleItemRenderer
public boolean renderItem(ItemStack itemStack) {
public static ItemRenderer instance = new ItemRenderer();
public void renderTank(double x, double y, double z, FluidStack fluid, int capacity)
{
FluidTank tank = new FluidTank(fluid, capacity);
GL11.glPushMatrix();
GL11.glTranslated(0.02, 0.02, 0.02);
GL11.glScaled(0.92, 0.92, 0.92);
if (fluid != null)
{
GL11.glPushMatrix();
if (!fluid.getFluid().isGaseous())
{
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
FluidRenderUtility.renderFluidTesselation(tank, percentageFilled, percentageFilled, percentageFilled, percentageFilled);
}
else
{
double filledPercentage = (double) fluid.amount / (double) capacity;
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);
Color color = new Color(fluid.getFluid().getColor());
RenderUtility.enableBlending();
GL11.glColor4d(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, fluid.getFluid().isGaseous() ? filledPercentage : 1);
RenderUtility.bind(FluidRenderUtility.getFluidSheet(fluid));
FluidRenderUtility.renderFluidTesselation(tank, 1, 1, 1, 1);
RenderUtility.disableBlending();
GL11.glPopAttrib();
}
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
@Override
public void renderInventoryItem(ItemStack itemStack)
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(0.5, 0.5, 0.5);
RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage(), Archaic.blockTank, null, RenderUtility.getIcon(Reference.PREFIX + "tankEdge")); RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage(), Archaic.blockTank, null, RenderUtility.getIcon(Reference.PREFIX + "tankEdge"));
GL11.glPopMatrix(); GL11.glPopMatrix();
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(0, -0.1, 0);
FluidStack fluid = null;
if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid")) if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid"))
{ {
fluid = FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound().getCompoundTag("fluid")); renderTank(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound().getCompoundTag("fluid")), VOLUME * FluidContainerRegistry.BUCKET_VOLUME);
} }
renderTank(TileTank.this, 0, 0, 0, fluid);
GL11.glPopMatrix(); GL11.glPopMatrix();
return true;
} }
};
} }
@Override @Override