Moved RenderItemOverlayTile

This commit is contained in:
Calclavia 2014-03-15 18:22:04 +08:00
parent 46211efae1
commit 09810e27de
9 changed files with 28 additions and 260 deletions

View file

@ -1,16 +1,17 @@
package resonantinduction.archaic.crate;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.render.RenderItemOverlayTile;
import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.utility.LanguageUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderCrate extends RenderItemOverlayTile
public class RenderCrate extends TileEntitySpecialRenderer
{
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
@ -19,7 +20,7 @@ public class RenderCrate extends RenderItemOverlayTile
{
GL11.glPushMatrix();
TileCrate tile = (TileCrate) tileEntity;
renderItemOnSides(tileEntity, tile.getSampleStack(), x, y, z, LanguageUtility.getLocal("tooltip.empty"));
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getSampleStack(), x, y, z, LanguageUtility.getLocal("tooltip.empty"));
GL11.glPopMatrix();
}
}

View file

@ -25,7 +25,6 @@ import org.lwjgl.opengl.GL11;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.prefab.imprint.ItemImprint;
import resonantinduction.core.render.RenderItemOverlayTile;
import universalelectricity.api.vector.Vector2;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.content.module.TileRender;
@ -37,6 +36,7 @@ import calclavia.lib.prefab.item.ItemBlockSaved;
import calclavia.lib.prefab.slot.ISlotPickResult;
import calclavia.lib.prefab.tile.IRotatable;
import calclavia.lib.prefab.vector.Cuboid;
import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.utility.WorldUtility;
import calclavia.lib.utility.inventory.AutoCraftingManager;
import calclavia.lib.utility.inventory.AutoCraftingManager.IAutoCrafter;
@ -736,8 +736,8 @@ public class TileEngineeringTable extends TileInventory implements IPacketReceiv
if (!isItem)
{
GL11.glPushMatrix();
RenderItemOverlayTile.renderItemOnSides(TileEngineeringTable.this, getStackInSlot(9), position.x, position.y, position.z);
RenderItemOverlayTile.renderTopOverlay(TileEngineeringTable.this, craftingMatrix, getDirection(), position.x, position.y - 0.1, position.z);
RenderItemOverlayUtility.renderItemOnSides(TileEngineeringTable.this, getStackInSlot(9), position.x, position.y, position.z);
RenderItemOverlayUtility.renderTopOverlay(TileEngineeringTable.this, craftingMatrix, getDirection(), position.x, position.y - 0.1, position.z);
GL11.glPopMatrix();
}

View file

@ -1,14 +1,15 @@
package resonantinduction.archaic.filter;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.render.RenderItemOverlayTile;
import calclavia.lib.render.RenderItemOverlayUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderImprinter extends RenderItemOverlayTile
public class RenderImprinter extends TileEntitySpecialRenderer
{
private final RenderBlocks renderBlocks = new RenderBlocks();
@ -18,8 +19,8 @@ public class RenderImprinter extends RenderItemOverlayTile
if (tileEntity instanceof TileImprinter)
{
TileImprinter tile = (TileImprinter) tileEntity;
renderTopOverlay(tileEntity, tile.inventory, ForgeDirection.EAST, x, y, z);
renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
RenderItemOverlayUtility.renderTopOverlay(tileEntity, tile.inventory, ForgeDirection.EAST, x, y, z);
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getStackInSlot(9), x, y, z);
}
}
}

View file

@ -15,7 +15,6 @@ import net.minecraftforge.fluids.IFluidHandler;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.prefab.imprint.ItemImprint;
import resonantinduction.core.prefab.imprint.TileFilterable;
import resonantinduction.core.render.RenderItemOverlayTile;
import resonantinduction.core.resource.ResourceGenerator;
import resonantinduction.core.resource.fluid.BlockFluidMixture;
import universalelectricity.api.vector.Vector3;
@ -27,6 +26,7 @@ import calclavia.lib.content.module.TileRender;
import calclavia.lib.network.Synced.SyncedInput;
import calclavia.lib.network.Synced.SyncedOutput;
import calclavia.lib.prefab.vector.Cuboid;
import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.utility.LanguageUtility;
import calclavia.lib.utility.inventory.InventoryUtility;
import cpw.mods.fml.relauncher.Side;
@ -155,7 +155,7 @@ public class TileFilter extends TileFilterable implements IFilterable
if (filteredStacks.size() > 0)
{
ItemStack renderStack = filteredStacks.get(renderIndex);
RenderItemOverlayTile.renderItemOnSides(TileFilter.this, renderStack, position.x, position.y, position.z);
RenderItemOverlayUtility.renderItemOnSides(TileFilter.this, renderStack, position.x, position.y, position.z);
}
}

View file

@ -1,14 +1,15 @@
package resonantinduction.archaic.firebox;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.render.RenderItemOverlayTile;
import calclavia.lib.render.RenderItemOverlayUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderHotPlate extends RenderItemOverlayTile
public class RenderHotPlate extends TileEntitySpecialRenderer
{
private final RenderBlocks renderBlocks = new RenderBlocks();
@ -18,7 +19,7 @@ public class RenderHotPlate extends RenderItemOverlayTile
if (tileEntity instanceof TileHotPlate)
{
TileHotPlate tile = (TileHotPlate) tileEntity;
renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), ForgeDirection.EAST, 2, 2, x, y - 0.8, z, 1f);
RenderItemOverlayUtility.renderTopOverlay(tileEntity, tile.getInventory().getContainedItems(), ForgeDirection.EAST, 2, 2, x, y - 0.8, z, 1f);
}
}
}

View file

@ -1,5 +1,6 @@
package resonantinduction.archaic.process;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
@ -7,13 +8,13 @@ import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import resonantinduction.core.render.RenderItemOverlayTile;
import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.render.RenderUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderCastingMold extends RenderItemOverlayTile
public class RenderCastingMold extends TileEntitySpecialRenderer
{
public static RenderCastingMold INSTANCE = new RenderCastingMold();
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(Reference.MODEL_DIRECTORY + "castingMold.tcn");
@ -34,7 +35,7 @@ public class RenderCastingMold extends RenderItemOverlayTile
GL11.glPopMatrix();
if (tile.worldObj != null)
renderItemOnSides(tileEntity, tile.getStackInSlot(0), x, y, z, "");
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getStackInSlot(0), x, y, z, "");
}
}
}

View file

@ -1,13 +1,14 @@
package resonantinduction.archaic.process;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import resonantinduction.core.render.RenderItemOverlayTile;
import calclavia.lib.render.RenderItemOverlayUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderMillstone extends RenderItemOverlayTile
public class RenderMillstone extends TileEntitySpecialRenderer
{
private final RenderBlocks renderBlocks = new RenderBlocks();
@ -17,7 +18,7 @@ public class RenderMillstone extends RenderItemOverlayTile
if (tileEntity instanceof TileMillstone)
{
TileMillstone tile = (TileMillstone) tileEntity;
renderItemOnSides(tileEntity, tile.getStackInSlot(0), x, y, z, "");
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getStackInSlot(0), x, y, z, "");
}
}
}

View file

@ -12,11 +12,11 @@ import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import resonantinduction.core.render.RenderItemOverlayTile;
import universalelectricity.api.CompatibilityModule;
import universalelectricity.api.energy.UnitDisplay;
import universalelectricity.api.energy.UnitDisplay.Unit;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.render.RenderItemOverlayUtility;
import calclavia.lib.render.RenderUtility;
import calclavia.lib.render.item.ISimpleItemRenderer;
@ -54,7 +54,7 @@ public class RenderCharger implements ISimpleItemRenderer
RenderUtility.rotateFaceToSideNoTranslate(part.placementSide);
RenderUtility.rotateBlockBasedOnDirection(part.getFacing());
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
RenderItemOverlayTile.renderItem(part.world(), part.placementSide, part.getStackInSlot(0), new Vector3(0.00, -0.3, -0.00), 0, 4);
RenderItemOverlayUtility.renderItem(part.world(), part.placementSide, part.getStackInSlot(0), new Vector3(0.00, -0.3, -0.00), 0, 4);
GL11.glPopMatrix();
EntityPlayer player = Minecraft.getMinecraft().thePlayer;

View file

@ -1,237 +0,0 @@
package resonantinduction.core.render;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import universalelectricity.api.vector.Vector3;
import calclavia.lib.render.RenderUtility;
import calclavia.lib.utility.LanguageUtility;
import calclavia.lib.utility.WorldUtility;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public abstract class RenderItemOverlayTile extends TileEntitySpecialRenderer
{
private static final ForgeDirection[] forge_sides = { ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST };
private static RenderBlocks renderBlocks;
private static RenderItem renderItem;
public RenderItemOverlayTile()
{
super();
renderItem = ((RenderItem) RenderManager.instance.getEntityClassRenderObject(EntityItem.class));
renderBlocks = new RenderBlocks();
}
public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, double x, double y, double z)
{
renderTopOverlay(tileEntity, inventory, dir, 3, 3, x, y, z, 0.7f);
}
public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z, float scale)
{
GL11.glPushMatrix();
/** Render the Crafting Matrix */
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
boolean isLooking = false;
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null)
{
isLooking = objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
}
for (int i = 0; i < (matrixX * matrixZ); i++)
{
if (inventory[i] != null)
{
Vector3 translation = new Vector3((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).translate(-0.5);
translation.scale(0.85);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x, translation.y, translation.z);
GL11.glScalef(scale, scale, scale);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
renderItem(tileEntity.worldObj, ForgeDirection.UP, inventory[i], new Vector3(0, 0, 0), 0, 4);
GL11.glPopMatrix();
if (isLooking)
{
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
int angle = WorldUtility.getAngleFromForgeDirection(WorldUtility.invertX(dir));
RenderUtility.renderFloatingText("" + inventory[i].stackSize, translation.rotate(angle, Vector3.UP()).translate(0.5).translate(0, 0.3, 0));
GL11.glPopMatrix();
}
}
}
GL11.glPopMatrix();
}
public static void renderItemOnSides(TileEntity tile, ItemStack itemStack, double x, double y, double z)
{
renderItemOnSides(tile, itemStack, x, y, z, LanguageUtility.getLocal("tooltip.noOutput"));
}
public static void renderItemOnSides(TileEntity tile, ItemStack itemStack, double x, double y, double z, String renderText)
{
/** Render the Output */
String amount = "";
if (itemStack != null)
{
renderText = itemStack.getDisplayName();
amount = Integer.toString(itemStack.stackSize);
}
for (ForgeDirection direction : forge_sides)
{
if (tile.worldObj.isBlockSolidOnSide(tile.xCoord + direction.offsetX, tile.yCoord, tile.zCoord + direction.offsetZ, direction.getOpposite()))
{
continue;
}
renderItemOnSide(tile, itemStack, direction, x, y, z, renderText, amount);
GL11.glPushMatrix();
setupLight(tile, direction.offsetX, direction.offsetZ);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
GL11.glDisable(2896);
RenderUtility.renderText(renderText, direction, 0.02f, x, y - 0.35f, z);
RenderUtility.renderText(amount, direction, 0.02f, x, y - 0.15f, z);
GL11.glEnable(2896);
GL11.glPopMatrix();
}
}
protected static void renderItemSingleSide(TileEntity tile, double x, double y, double z, ItemStack itemStack, ForgeDirection direction, String renderText)
{
if (!tile.worldObj.isBlockSolidOnSide(tile.xCoord + direction.offsetX, tile.yCoord, tile.zCoord + direction.offsetZ, direction.getOpposite()))
{
String amount = "";
if (itemStack != null)
{
renderText = itemStack.getDisplayName();
amount = Integer.toString(itemStack.stackSize);
}
renderItemOnSide(tile, itemStack, direction, x, y, z, renderText, amount);
GL11.glPushMatrix();
setupLight(tile, direction.offsetX, direction.offsetZ);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
GL11.glDisable(2896);
RenderUtility.renderText(renderText, direction, 0.02f, x, y - 0.35f, z);
RenderUtility.renderText(amount, direction, 0.02f, x, y - 0.15f, z);
GL11.glEnable(2896);
GL11.glPopMatrix();
}
}
protected static void renderItemOnSide(TileEntity tile, ItemStack itemStack, ForgeDirection direction, double x, double y, double z, String renderText, String amount)
{
if (itemStack != null)
{
GL11.glPushMatrix();
switch (direction)
{
case NORTH:
GL11.glTranslated(x + 0.65, y + 0.9, z - 0.01);
break;
case SOUTH:
GL11.glTranslated(x + 0.35, y + 0.9, z + 1.01);
GL11.glRotatef(180, 0, 1, 0);
break;
case WEST:
GL11.glTranslated(x - 0.01, y + 0.9, z + 0.35);
GL11.glRotatef(90, 0, 1, 0);
break;
case EAST:
GL11.glTranslated(x + 1.01, y + 0.9, z + 0.65);
GL11.glRotatef(-90, 0, 1, 0);
break;
}
float scale = 0.03125F;
GL11.glScalef(0.6f * scale, 0.6f * scale, -0.00001f);
GL11.glRotatef(180, 0, 0, 1);
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
setupLight(tile, direction.offsetX, direction.offsetZ);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
GL11.glDisable(2896);
if (!ForgeHooksClient.renderInventoryItem(renderBlocks, renderEngine, itemStack, true, 0.0F, 0.0F, 0.0F))
{
renderItem.renderItemIntoGUI(Minecraft.getMinecraft().fontRenderer, renderEngine, itemStack, 0, 0);
}
GL11.glEnable(2896);
GL11.glPopMatrix();
}
}
private static void setupLight(TileEntity tileEntity, int xDifference, int zDifference)
{
World world = tileEntity.worldObj;
if (world.isBlockOpaqueCube(tileEntity.xCoord + xDifference, tileEntity.yCoord, tileEntity.zCoord + zDifference))
{
return;
}
int br = world.getLightBrightnessForSkyBlocks(tileEntity.xCoord + xDifference, tileEntity.yCoord, tileEntity.zCoord + zDifference, 0);
int var11 = br % 65536;
int var12 = br / 65536;
float scale = 1;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, var11 * scale, var12 * scale);
}
public static void renderItem(World world, ForgeDirection dir, ItemStack itemStack, Vector3 position, float rotationYaw, int angle)
{
if (itemStack != null)
{
EntityItem entityItem = new EntityItem(world, 0.0D, 0.0D, 0.0D, itemStack.copy());
entityItem.getEntityItem().stackSize = 1;
entityItem.hoverStart = 0.0F;
GL11.glPushMatrix();
GL11.glTranslated(position.x, position.y, -position.z);
GL11.glRotatef(180.0F + rotationYaw, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(90 * angle, 1, 0, 0);
RenderItem renderItem = ((RenderItem) RenderManager.instance.getEntityClassRenderObject(EntityItem.class));
boolean fancyGraphics = RenderManager.instance.options.fancyGraphics;
RenderManager.instance.options.fancyGraphics = true;
renderItem.doRenderItem(entityItem, 0, 0, 0, 0, 0);
RenderManager.instance.options.fancyGraphics = fancyGraphics;
GL11.glPopMatrix();
}
}
}