Skip to content

Instantly share code, notes, and snippets.

@MultiMote
Created July 26, 2014 16:33
Show Gist options
  • Save MultiMote/fa5a34df802f0d82d428 to your computer and use it in GitHub Desktop.
Save MultiMote/fa5a34df802f0d82d428 to your computer and use it in GitHub Desktop.
package com.multimote.microz.block.render;
import com.multimote.microz.block.electricity.NormalWireBlock;
import com.multimote.microz.entity.render.model.SimpleBox;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
/**
* Created by multimote on 26.07.14.
*/
public class WireRenderer extends TileEntitySpecialRenderer {
private static SimpleBox box = new SimpleBox(16, 4, 4);
private static SimpleBox boxextra = new SimpleBox(6, 4, 4, 0, 8);
private static SimpleBox boxcenter = new SimpleBox(4, 4, 4, 0, 16);
private static ResourceLocation tex = new ResourceLocation("microz:textures/modelled/wire.png");
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float var8) {
GL11.glPushMatrix();
Minecraft.getMinecraft().renderEngine.bindTexture(tex);
float f = 1F / 16F;
GL11.glTranslated(x + 0.5, y + (0.5 - f * 2), z + 0.5);
boolean xConnected = false;
boolean yConnected = false;
boolean zConnected = false;
int sides = 0;
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord + 1, tile.yCoord, tile.zCoord)) {
sides |= (1 << 1);
xConnected = true;
}
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord - 1, tile.yCoord, tile.zCoord)) {
sides |= (1 << 2);
xConnected = true;
}
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord, tile.yCoord + 1, tile.zCoord)) {
sides |= (1 << 3);
yConnected = true;
}
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord, tile.yCoord - 1, tile.zCoord)) {
sides |= (1 << 4);
yConnected = true;
}
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord + 1)) {
sides |= (1 << 5);
zConnected = true;
}
if (NormalWireBlock.isConnectable(tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord - 1)) {
sides |= (1 << 6);
zConnected = true;
}
if (xConnected || yConnected || zConnected) {
boolean flag = false;
if (xConnected && !yConnected && !zConnected) {
box.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
flag = true;
} else {
if (((sides >> 1) & 1) != 0) {
GL11.glTranslatef(f * 5, 0, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(-f * 5, 0, 0);
}
if (((sides >> 2) & 1) != 0) {
GL11.glTranslatef(-f * 5, 0, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(f * 5, 0, 0);
}
}
if (!xConnected && yConnected && !zConnected) {
GL11.glRotatef(90F, 0, 0, 1);
GL11.glTranslatef(f * 2, -f * 2, 0);
box.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(-f * 2, f * 2, 0);
GL11.glRotatef(-90F, 0, 0, 1);
flag = true;
} else {
if (((sides >> 3) & 1) != 0) {
GL11.glRotatef(90F, 0, 0, 1);
GL11.glTranslatef(f * 7, -f * 2, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(-f * 7, f * 2, 0);
GL11.glRotatef(-90F, 0, 0, 1);
}
if (((sides >> 4) & 1) != 0) {
GL11.glRotatef(90F, 0, 0, 1);
GL11.glTranslatef(-f * 3, -f * 2, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(f * 3, f * 2, 0);
GL11.glRotatef(-90F, 0, 0, 1);
}
}
if (!xConnected && !yConnected && zConnected) {
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
box.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F);
flag = true;
} else {
if (((sides >> 5) & 1) != 0) {
GL11.glRotatef(90F, 0, 1, 0);
GL11.glTranslatef(-f * 5, 0, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(f * 5, 0, 0);
GL11.glRotatef(-90F, 0, 1, 0);
}
if (((sides >> 6) & 1) != 0) {
GL11.glRotatef(90F, 0, 1, 0);
GL11.glTranslatef(f * 5, 0, 0);
boxextra.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
GL11.glTranslatef(-f * 5, 0, 0);
GL11.glRotatef(-90F, 0, 1, 0);
}
}
if (!flag) boxcenter.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
} else {
float rotation = tile.getBlockMetadata() % 2 == 0 ? 90F : 0F;
GL11.glRotatef(rotation, 0.0F, 1.0F, 0.0F);
box.render(null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F);
}
GL11.glPopMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment