Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tahgcraft.lca.client;
- import java.awt.geom.Rectangle2D;
- import java.util.HashMap;
- import org.lwjgl.opengl.GL11;
- import com.tahgcraft.lca.common.LCA;
- import com.tahgcraft.lca.common.TileEntityHybridProjector;
- import net.minecraft.block.Block;
- import net.minecraft.client.model.PositionTextureVertex;
- import net.minecraft.client.model.TexturedQuad;
- 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.SimpleTexture;
- import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.Vec3;
- public class TileEntityHybridProjectorRenderer extends TileEntitySpecialRenderer {
- private static final ResourceLocation RSC_PROJECTOR = new ResourceLocation("lca:textures/entities/projector.png");
- static HashMap<ResourceLocation, SimpleTexture> textures = new HashMap<ResourceLocation, SimpleTexture>();
- ModelProjector projector = new ModelProjector();
- RenderItem ri = null;
- TexturedQuad quad = new TexturedQuad(new PositionTextureVertex[] {
- new PositionTextureVertex(-.5F, -.5F, 0, 0, 0),
- new PositionTextureVertex(.5F, -.5F, 0, 1, 0),
- new PositionTextureVertex(.5F, .5F, 0, 1, 1),
- new PositionTextureVertex(-.5F, .5F, 0, 0, 1)});
- public void renderTileEntityAt(TileEntityHybridProjector entity, double x, double y, double z, float f) {
- int meta = entity.getWorldObj().getBlockMetadata(entity.xCoord, entity.yCoord, entity.zCoord);
- int dir = meta & 3;
- Block block = entity.getWorldObj().getBlock(entity.xCoord, entity.yCoord, entity.zCoord);
- bindTexture(RSC_PROJECTOR);
- GL11.glPushMatrix();
- GL11.glTranslated(x + .5, y + .5, z + .5);
- GL11.glScaled(1, -1, -1);
- GL11.glColor3f(1, 1, 1);
- GL11.glRotated(90 * (dir + 2), 0, 1, 0);
- if (block == LCA.blockVerticalProjector) {
- GL11.glRotated(90, 1, 0, 0);
- }
- if (entity.location == null) entity.setPictureLocation();
- ResourceLocation location = entity.location;
- projector.renderAll(location != null);
- if (block == LCA.blockVerticalProjector) {
- GL11.glRotated(-90, 1, 0, 0);
- }
- if (location != null && entity.hasPower()) {
- String name = entity.getRawImageName();
- int dmgOffset = name.indexOf('@');
- int damage = 0;
- if (dmgOffset > 0) {
- try {
- damage = Integer.parseInt(name.substring(dmgOffset + 1));
- }
- catch (Exception e) {
- }
- name = name.substring(0, dmgOffset);
- }
- Item item = (Item)Item.itemRegistry.getObject(name);
- Vec3 center = entity.getCenter();
- Vec3 size = entity.getSize();
- GL11.glTranslated(-center.xCoord, -center.yCoord, center.zCoord + .5);
- double yaw = entity.getRotation();
- double scale = entity.getScale();
- if (entity.getPeriod() != 0)
- yaw += (entity.getWorldObj().getTotalWorldTime() + f) / entity.getPeriod() / 20 * 360;
- GL11.glRotated(yaw, 0, 1, 0);
- if (item != null) {
- GL11.glScaled(-scale, -scale, scale);
- if (ri == null) {
- ri = new StaticRenderItem();
- ri.setRenderManager(RenderManager.instance);
- }
- EntityItem ei = new EntityItem(entity.getWorldObj(), 0, 0, 0, new ItemStack(item, 1, damage));
- ri.doRender(ei, 0, 0, 0, 0, 0);
- }
- else {
- GL11.glScaled(-size.xCoord * scale, size.yCoord * scale, 1);
- GL11.glDisable(GL11.GL_CULL_FACE);
- bindTexture(location);
- Rectangle2D.Double tex = entity.getTexCoords();
- quad.vertexPositions[0] = quad.vertexPositions[0].setTexturePosition((float) tex.getX(), (float) tex.getY());
- quad.vertexPositions[1] = quad.vertexPositions[1].setTexturePosition((float) (tex.getX() + tex.getWidth()), (float) tex.getY());
- quad.vertexPositions[2] = quad.vertexPositions[2].setTexturePosition((float) (tex.getX() + tex.getWidth()), (float) (tex.getY() + tex.getHeight()));
- quad.vertexPositions[3] = quad.vertexPositions[3].setTexturePosition((float) tex.getX(), (float) (tex.getY() + tex.getHeight()));
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- quad.draw(Tessellator.instance, 1);
- GL11.glDisable(GL11.GL_BLEND);
- GL11.glEnable(GL11.GL_CULL_FACE);
- }
- }
- GL11.glPopMatrix();
- }
- @Override
- public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) {
- renderTileEntityAt((TileEntityHybridProjector)entity, x, y, z, f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement