mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
basic rendering of items inside MSUs (on the north face only atm) complete
This commit is contained in:
parent
4032cc277a
commit
18a4d7a25a
@ -442,6 +442,8 @@ public class ClientProxy extends ServerProxy {
|
|||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVaultDoor.class, new RenderVaultDoor());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityVaultDoor.class, new RenderVaultDoor());
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBlastDoor.class, new RenderBlastDoor());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBlastDoor.class, new RenderBlastDoor());
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDoorGeneric.class, new RenderDoorGeneric());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDoorGeneric.class, new RenderDoorGeneric());
|
||||||
|
//storage
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityMassStorage.class, new RenderMassStorage());
|
||||||
//NBTStructure
|
//NBTStructure
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWandStructure.class, new RenderWandStructure());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityWandStructure.class, new RenderWandStructure());
|
||||||
}
|
}
|
||||||
|
|||||||
229
src/main/java/com/hbm/render/tileentity/RenderMassStorage.java
Normal file
229
src/main/java/com/hbm/render/tileentity/RenderMassStorage.java
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
package com.hbm.render.tileentity;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import com.hbm.tileentity.machine.storage.TileEntityMassStorage;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import net.minecraft.client.renderer.RenderBlocks;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
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.texture.TextureMap;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class RenderMassStorage extends TileEntitySpecialRenderer {
|
||||||
|
|
||||||
|
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||||
|
|
||||||
|
private RenderItem itemRenderer = new RenderItem() {
|
||||||
|
|
||||||
|
private RenderBlocks renderBlocksRi = new RenderBlocks();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte getMiniBlockCount(ItemStack stack, byte original) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldBob() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldSpreadItems() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The default Mojang code for item render does not handle glinted or multi-pass items gracefully in a non-UI
|
||||||
|
// setting. This modified implementation will render these items without unsightly Z-fighting.
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderItemIntoGUI (FontRenderer fontRenderer, TextureManager texManager, ItemStack itemStack, int x, int y, boolean renderEffect) {
|
||||||
|
if(itemStack.getItemSpriteNumber() == 0 && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType())) {
|
||||||
|
renderItemIntoGUIBlock(fontRenderer, texManager, itemStack, x, y, renderEffect);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Item item = itemStack.getItem();
|
||||||
|
int meta = itemStack.getItemDamage();
|
||||||
|
|
||||||
|
ResourceLocation loc = itemStack.getItem().requiresMultipleRenderPasses()
|
||||||
|
? (item.getSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture)
|
||||||
|
: (texManager.getResourceLocation(itemStack.getItemSpriteNumber()));
|
||||||
|
|
||||||
|
for(int i = 0; i < item.getRenderPasses(meta); ++i) {
|
||||||
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||||
|
texManager.bindTexture(loc);
|
||||||
|
|
||||||
|
IIcon icon = itemStack.getItem().requiresMultipleRenderPasses()
|
||||||
|
? item.getIcon(itemStack, i)
|
||||||
|
: itemStack.getIconIndex();
|
||||||
|
|
||||||
|
if(icon == null) continue;
|
||||||
|
|
||||||
|
int color = itemStack.getItem().getColorFromItemStack(itemStack, i);
|
||||||
|
float r = (float)(color >> 16 & 255) / 255.0F;
|
||||||
|
float g = (float)(color >> 8 & 255) / 255.0F;
|
||||||
|
float b = (float)(color & 255) / 255.0F;
|
||||||
|
|
||||||
|
if(renderWithColor)
|
||||||
|
GL11.glColor4f(r, g, b, 1.0F);
|
||||||
|
|
||||||
|
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||||
|
GL11.glPolygonOffset(-1f, -1);
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
|
||||||
|
renderIcon(x, y, icon, 16, 16);
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
|
||||||
|
if(renderEffect && itemStack.hasEffect(i))
|
||||||
|
renderEffect(texManager, x, y);
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderEffect (TextureManager manager, int x, int y) {
|
||||||
|
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
manager.bindTexture(RES_ITEM_GLINT);
|
||||||
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
|
||||||
|
renderGlint(x, y, 16, 16);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderGlint (int x, int y, int w, int h) {
|
||||||
|
for(int i = 0; i < 2; ++i) {
|
||||||
|
OpenGlHelper.glBlendFunc(772, 1, 0, 0);
|
||||||
|
float uScale = 0.00390625F;
|
||||||
|
float vScale = 0.00390625F;
|
||||||
|
float u = (Minecraft.getSystemTime() % (3000 + i * 1873)) / (3000.0F + i * 1873) * 256.0F;
|
||||||
|
float v = 0.0F;
|
||||||
|
|
||||||
|
float hScale = (i < 1) ? 4.0F : -1.0F;
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
tessellator.addVertexWithUV(x + 0, y + h, 0, (u + (float)h * hScale) * uScale, (v + (float)h) * vScale);
|
||||||
|
tessellator.addVertexWithUV(x + w, y + h, 0, (u + (float)w + (float)h * hScale) * uScale, (v + (float)h) * vScale);
|
||||||
|
tessellator.addVertexWithUV(x + w, y + 0, 0, (u + (float)w) * uScale, (v + 0.0F) * vScale);
|
||||||
|
tessellator.addVertexWithUV(x + 0, y + 0, 0, (u + 0.0F) * uScale, (v + 0.0F) * vScale);
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderItemIntoGUIBlock (FontRenderer fontRenderer, TextureManager texManager, ItemStack itemStack, int x, int y, boolean renderEffect) {
|
||||||
|
texManager.bindTexture(TextureMap.locationBlocksTexture);
|
||||||
|
Block block = Block.getBlockFromItem(itemStack.getItem());
|
||||||
|
|
||||||
|
if(block.getRenderBlockPass() != 0) {
|
||||||
|
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||||
|
} else {
|
||||||
|
GL11.glAlphaFunc(GL11.GL_GREATER, 0.5F);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(x - 2, y + 3, zLevel - 3);
|
||||||
|
GL11.glScalef(10, 10, 10);
|
||||||
|
GL11.glTranslatef(1, 0.5f, 1);
|
||||||
|
GL11.glScalef(1, 1, -1);
|
||||||
|
GL11.glRotatef(210, 1, 0, 0);
|
||||||
|
GL11.glRotatef(45, 0, 1, 0);
|
||||||
|
|
||||||
|
int color = itemStack.getItem().getColorFromItemStack(itemStack, 0);
|
||||||
|
float r = (float)(color >> 16 & 255) / 255.0F;
|
||||||
|
float g = (float)(color >> 8 & 255) / 255.0F;
|
||||||
|
float b = (float)(color & 255) / 255.0F;
|
||||||
|
|
||||||
|
if(this.renderWithColor)
|
||||||
|
GL11.glColor4f(r * 1, g * 1, b * 1, 1.0F);
|
||||||
|
|
||||||
|
GL11.glRotatef(-90, 0, 1, 0);
|
||||||
|
GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||||
|
GL11.glPolygonOffset(-1f, -1f);
|
||||||
|
|
||||||
|
this.renderBlocksRi.useInventoryTint = this.renderWithColor;
|
||||||
|
this.renderBlocksRi.renderBlockAsItem(block, itemStack.getItemDamage(), 1);
|
||||||
|
this.renderBlocksRi.useInventoryTint = true;
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
|
||||||
|
|
||||||
|
if(block.getRenderBlockPass() == 0)
|
||||||
|
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float interp) {
|
||||||
|
if(!(tile instanceof TileEntityMassStorage)) return;
|
||||||
|
TileEntityMassStorage storage = (TileEntityMassStorage) tile;
|
||||||
|
|
||||||
|
if(storage.type == null) return;
|
||||||
|
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
World world = tile.getWorldObj();
|
||||||
|
ForgeDirection dir = storage.getDirection();
|
||||||
|
|
||||||
|
itemRenderer.setRenderManager(RenderManager.instance);
|
||||||
|
|
||||||
|
int ambLight = world.getLightBrightnessForSkyBlocks(tile.xCoord + dir.offsetX, tile.yCoord + dir.offsetY, tile.zCoord + dir.offsetZ, 0);
|
||||||
|
int lu = ambLight % 65536;
|
||||||
|
int lv = ambLight / 65536;
|
||||||
|
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lu, lv);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
{
|
||||||
|
|
||||||
|
// align to block
|
||||||
|
GL11.glTranslated(x, y, z);
|
||||||
|
|
||||||
|
// align item (and flip)
|
||||||
|
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
|
||||||
|
GL11.glRotatef(180.0F, 0, 0, 1);
|
||||||
|
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
|
||||||
|
|
||||||
|
// move and scale item
|
||||||
|
GL11.glTranslatef(0, 0, -0.005F);
|
||||||
|
GL11.glScalef(1.0F / 16.0F, 1.0F / 16.0F, -0.0001F);
|
||||||
|
|
||||||
|
itemRenderer.renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, storage.type, 0, 0, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,6 +20,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPacketReceiver, IControlReceiverFilter, IRORValueProvider, IRORInteractive {
|
public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPacketReceiver, IControlReceiverFilter, IRORValueProvider, IRORInteractive {
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
networkPackNT(15);
|
networkPackNT(64); // TE render distance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Note: the following three methods are used for AE2 integration, and aren't meant to be called in any other context by default
|
// Note: the following three methods are used for AE2 integration, and aren't meant to be called in any other context by default
|
||||||
|
|
||||||
public int getTotalStockpile() {
|
public int getTotalStockpile() {
|
||||||
ItemStack type = getType();
|
ItemStack type = getType();
|
||||||
if(type == null) return 0;
|
if(type == null) return 0;
|
||||||
@ -174,7 +175,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
}
|
}
|
||||||
amount -= depositStockpile;
|
amount -= depositStockpile;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inputAvail = 0;
|
int inputAvail = 0;
|
||||||
ItemStack inStack = slots[0];
|
ItemStack inStack = slots[0];
|
||||||
if(inStack != null && ItemStackUtil.areStacksCompatible(type, inStack)) {
|
if(inStack != null && ItemStackUtil.areStacksCompatible(type, inStack)) {
|
||||||
@ -197,7 +198,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
}
|
}
|
||||||
amount -= depositInput;
|
amount -= depositInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
int outputAvail = 0;
|
int outputAvail = 0;
|
||||||
ItemStack outStack = slots[2];
|
ItemStack outStack = slots[2];
|
||||||
if(outStack != null && ItemStackUtil.areStacksCompatible(type, outStack)) {
|
if(outStack != null && ItemStackUtil.areStacksCompatible(type, outStack)) {
|
||||||
@ -224,7 +225,7 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
if(actually) {
|
if(actually) {
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,6 +259,10 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ForgeDirection getDirection() {
|
||||||
|
return ForgeDirection.NORTH;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(EntityPlayer player) {
|
public boolean hasPermission(EntityPlayer player) {
|
||||||
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
return Vec3.createVectorHelper(xCoord - player.posX, yCoord - player.posY, zCoord - player.posZ).lengthVector() < 20;
|
||||||
@ -389,12 +394,12 @@ public class TileEntityMassStorage extends TileEntityCrateBase implements IBufPa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String runRORFunction(String name, String[] params) {
|
public String runRORFunction(String name, String[] params) {
|
||||||
|
|
||||||
if((PREFIX_FUNCTION + "toggleoutput").equals(name)) {
|
if((PREFIX_FUNCTION + "toggleoutput").equals(name)) {
|
||||||
this.output = !this.output;
|
this.output = !this.output;
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user