Fixed tank item rendering
This commit is contained in:
parent
91f402b18f
commit
ffa9be03d5
3 changed files with 232 additions and 185 deletions
|
@ -1,9 +1,13 @@
|
|||
package resonantinduction.archaic;
|
||||
|
||||
import resonant.lib.render.item.GlobalItemRenderer;
|
||||
import resonantinduction.archaic.fluid.tank.TileTank;
|
||||
|
||||
public class ClientProxy extends CommonProxy
|
||||
{
|
||||
@Override
|
||||
public void preInit()
|
||||
{
|
||||
GlobalItemRenderer.register(Archaic.blockTank.blockID, TileTank.ItemRenderer.instance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,212 +9,211 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
import resonant.lib.utility.LanguageUtility;
|
||||
import resonantinduction.archaic.Archaic;
|
||||
import resonantinduction.core.grid.fluid.TileFluidDistribution;
|
||||
import universalelectricity.api.energy.UnitDisplay;
|
||||
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||
import universalelectricity.api.energy.UnitDisplay.UnitPrefix;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
/** @author Darkguardsman */
|
||||
/**
|
||||
* @author Darkguardsman
|
||||
*/
|
||||
public class ItemBlockTank extends ItemBlock implements IFluidContainerItem
|
||||
{
|
||||
public ItemBlockTank(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
public ItemBlockTank(int id)
|
||||
{
|
||||
super(id);
|
||||
this.setMaxDamage(0);
|
||||
this.setHasSubtypes(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
@Override
|
||||
public int getMetadata(int damage)
|
||||
{
|
||||
return damage;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
|
||||
{
|
||||
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
|
||||
{
|
||||
FluidStack fluid = getFluid(stack);
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
|
||||
{
|
||||
if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid"))
|
||||
{
|
||||
FluidStack fluid = getFluid(itemStack);
|
||||
|
||||
if (fluid != null)
|
||||
{
|
||||
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
|
||||
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fluid != null)
|
||||
{
|
||||
list.add("Fluid: " + fluid.getFluid().getLocalizedName());
|
||||
list.add("Volume: " + UnitDisplay.getDisplay(fluid.amount, Unit.LITER, UnitPrefix.MILLI));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack)
|
||||
{
|
||||
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return this.maxStackSize;
|
||||
}
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack)
|
||||
{
|
||||
if (stack.getTagCompound() != null && stack.getTagCompound().hasKey("fluid"))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return this.maxStackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
String translation = LanguageUtility.getLocal(Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage());
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemStack)
|
||||
{
|
||||
String translation = LanguageUtility.getLocal(Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage());
|
||||
|
||||
if (translation == null || translation.isEmpty())
|
||||
{
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName();
|
||||
}
|
||||
if (translation == null || translation.isEmpty())
|
||||
{
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName();
|
||||
}
|
||||
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
|
||||
}
|
||||
return Block.blocksList[this.getBlockID()].getUnlocalizedName() + "." + itemStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
{
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
if (tile instanceof TileFluidDistribution)
|
||||
{
|
||||
((TileFluidDistribution) tile).setSubID(stack.getItemDamage());
|
||||
((TileFluidDistribution) tile).getInternalTank().fill(getFluid(stack), true);
|
||||
@Override
|
||||
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
|
||||
{
|
||||
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
|
||||
{
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
if (tile instanceof TileFluidDistribution)
|
||||
{
|
||||
((TileFluidDistribution) tile).setSubID(stack.getItemDamage());
|
||||
((TileFluidDistribution) tile).getInternalTank().fill(getFluid(stack), true);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack container)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
}
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack container)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack container)
|
||||
{
|
||||
return TileTank.VOLUME;
|
||||
}
|
||||
@Override
|
||||
public int getCapacity(ItemStack container)
|
||||
{
|
||||
return TileTank.VOLUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ItemStack container, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int fill(ItemStack container, FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!doFill)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
return Math.min(getCapacity(container), resource.amount);
|
||||
}
|
||||
if (!doFill)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
return Math.min(getCapacity(container), resource.amount);
|
||||
}
|
||||
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
|
||||
if (stack == null)
|
||||
{
|
||||
return Math.min(getCapacity(container), resource.amount);
|
||||
}
|
||||
if (stack == null)
|
||||
{
|
||||
return Math.min(getCapacity(container), resource.amount);
|
||||
}
|
||||
|
||||
if (!stack.isFluidEqual(resource))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!stack.isFluidEqual(resource))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.min(getCapacity(container) - stack.amount, resource.amount);
|
||||
}
|
||||
return Math.min(getCapacity(container) - stack.amount, resource.amount);
|
||||
}
|
||||
|
||||
if (container.stackTagCompound == null)
|
||||
{
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
if (container.stackTagCompound == null)
|
||||
{
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
if (!container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
|
||||
if (!container.stackTagCompound.hasKey("fluid"))
|
||||
{
|
||||
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
|
||||
|
||||
if (getCapacity(container) < resource.amount)
|
||||
{
|
||||
fluidTag.setInteger("Amount", getCapacity(container));
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
return getCapacity(container);
|
||||
}
|
||||
if (getCapacity(container) < resource.amount)
|
||||
{
|
||||
fluidTag.setInteger("Amount", getCapacity(container));
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
return getCapacity(container);
|
||||
}
|
||||
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
return resource.amount;
|
||||
}
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
return resource.amount;
|
||||
}
|
||||
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("fluid");
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("fluid");
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
|
||||
|
||||
if (!stack.isFluidEqual(resource))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!stack.isFluidEqual(resource))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int filled = getCapacity(container) - stack.amount;
|
||||
if (resource.amount < filled)
|
||||
{
|
||||
stack.amount += resource.amount;
|
||||
filled = resource.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.amount = getCapacity(container);
|
||||
}
|
||||
int filled = getCapacity(container) - stack.amount;
|
||||
if (resource.amount < filled)
|
||||
{
|
||||
stack.amount += resource.amount;
|
||||
filled = resource.amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.amount = getCapacity(container);
|
||||
}
|
||||
|
||||
container.stackTagCompound.setTag("fluid", stack.writeToNBT(fluidTag));
|
||||
return filled;
|
||||
}
|
||||
container.stackTagCompound.setTag("fluid", stack.writeToNBT(fluidTag));
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid") || maxDrain == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("fluid") || maxDrain == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag("fluid"));
|
||||
if (stack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int drained = Math.min(stack.amount, maxDrain);
|
||||
if (doDrain)
|
||||
{
|
||||
if (maxDrain >= stack.amount)
|
||||
{
|
||||
container.stackTagCompound.removeTag("fluid");
|
||||
int drained = Math.min(stack.amount, maxDrain);
|
||||
if (doDrain)
|
||||
{
|
||||
if (maxDrain >= stack.amount)
|
||||
{
|
||||
container.stackTagCompound.removeTag("fluid");
|
||||
|
||||
if (container.stackTagCompound.hasNoTags())
|
||||
{
|
||||
container.stackTagCompound = null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
if (container.stackTagCompound.hasNoTags())
|
||||
{
|
||||
container.stackTagCompound = null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("fluid");
|
||||
fluidTag.setInteger("Amount", fluidTag.getInteger("Amount") - maxDrain);
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
}
|
||||
stack.amount = drained;
|
||||
return stack;
|
||||
}
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag("fluid");
|
||||
fluidTag.setInteger("Amount", fluidTag.getInteger("Amount") - maxDrain);
|
||||
container.stackTagCompound.setTag("fluid", fluidTag);
|
||||
}
|
||||
stack.amount = drained;
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraftforge.fluids.FluidTank;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonant.api.IRemovable.ISneakPickup;
|
||||
import resonant.api.items.ISimpleItemRenderer;
|
||||
import resonant.lib.content.module.TileBlock.IComparatorInputOverride;
|
||||
import resonant.lib.content.module.TileRender;
|
||||
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 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 ySouthWest = percentageFilled;//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 yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
|
||||
double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, 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);
|
||||
}
|
||||
else
|
||||
|
@ -198,30 +199,73 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
|
|||
renderTank(TileTank.this, position.x, position.y, position.z, getInternalTank().getFluid());
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderItem(ItemStack itemStack)
|
||||
public static class ItemRenderer implements ISimpleItemRenderer
|
||||
{
|
||||
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();
|
||||
GL11.glTranslated(0.5, 0.5, 0.5);
|
||||
RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage(), Archaic.blockTank, null, RenderUtility.getIcon(Reference.PREFIX + "tankEdge"));
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(0, -0.1, 0);
|
||||
|
||||
FluidStack fluid = null;
|
||||
|
||||
if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid"))
|
||||
if (!fluid.getFluid().isGaseous())
|
||||
{
|
||||
fluid = FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound().getCompoundTag("fluid"));
|
||||
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();
|
||||
}
|
||||
|
||||
renderTank(TileTank.this, 0, 0, 0, fluid);
|
||||
GL11.glPopMatrix();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventoryItem(ItemStack itemStack)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
RenderBlockUtility.tessellateBlockWithConnectedTextures(itemStack.getItemDamage(), Archaic.blockTank, null, RenderUtility.getIcon(Reference.PREFIX + "tankEdge"));
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
if (itemStack.getTagCompound() != null && itemStack.getTagCompound().hasKey("fluid"))
|
||||
{
|
||||
renderTank(0, 0, 0, FluidStack.loadFluidStackFromNBT(itemStack.getTagCompound().getCompoundTag("fluid")), VOLUME * FluidContainerRegistry.BUCKET_VOLUME);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue