More glyph work - glyphs should now render as you expect in game (for the most part)

This commit is contained in:
Pahimar 2014-10-15 15:51:23 -04:00
parent 4b3dce914f
commit 42534f3509
5 changed files with 339 additions and 90 deletions

View file

@ -82,15 +82,16 @@ public class BlockAlchemyArray extends BlockEE implements ITileEntityProvider
{
((TileEntityEE) world.getTileEntity(x, y, z)).setOrientation(world.getBlockMetadata(x, y, z));
// TODO: Set rotation
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
if (!world.isRemote && world.getTileEntity(x, y, z) instanceof TileEntityAlchemyArray && entityLiving instanceof EntityPlayer)
{
NBTTagCompound customEntityData = EntityHelper.getCustomEntityData(entityLiving);
ChalkSettings chalkSettings = new ChalkSettings();
chalkSettings.readFromNBT(customEntityData);
// Set adjusted rotation
int facing = MathHelper.floor_double(entityLiving.rotationYaw * 4.0F / 360.0F + 0.5D) & 3;
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).setRotation(chalkSettings.getRotation(), facing);
ResourceLocation glyphTexture = GlyphTextureRegistry.getInstance().getResourceLocation(chalkSettings.getIndex());
((TileEntityAlchemyArray) world.getTileEntity(x, y, z)).addGlyphToAlchemyArray(new Glyph(glyphTexture, GlyphTextureRegistry.getInstance().getGlyphs().get(glyphTexture)), chalkSettings.getSize());

View file

@ -218,6 +218,8 @@ public class DrawBlockHighlightEventHandler
{
ChalkSettings chalkSettings = EquivalentExchange3.proxy.getClientProxy().chalkSettings;
ResourceLocation[] textures = GlyphTextureRegistry.getInstance().getGlyphs().keySet().toArray(new ResourceLocation[]{});
// TODO: Only intelligently render glyphs (and make them pulse)
RenderUtils.drawInWorldTransmutationOverlay(event, textures[chalkSettings.getIndex()], chalkSettings.getSize(), chalkSettings.getRotation());
}
}

View file

@ -6,7 +6,6 @@ import com.pahimar.ee3.tileentity.TileEntityAlchemyArray;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -22,92 +21,169 @@ public class TileEntityRendererAlchemyArray extends TileEntitySpecialRenderer
{
TileEntityAlchemyArray tileEntityAlchemyArray = (TileEntityAlchemyArray) FMLClientHandler.instance().getClient().theWorld.getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
int scale;
double xShift, yShift, zShift;
float xRotate, yRotate, zRotate;
int rotationAngle;
xShift = yShift = zShift = 0.5d;
xRotate = yRotate = zRotate = 0;
rotationAngle = 0;
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPushMatrix();
GL11.glDepthMask(false);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
for (Glyph glyph : tileEntityAlchemyArray.getAlchemyArray().getGlyphs())
{
GL11.glDepthMask(false);
scale = glyph.getSize();
if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.UP)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.NORTH)
{
rotationAngle = 0;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.EAST)
{
rotationAngle = -90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.SOUTH)
{
rotationAngle = 180;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.WEST)
{
rotationAngle = 90;
}
yShift = 0.001d;
xRotate = -1;
}
else if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.DOWN)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.NORTH)
{
rotationAngle = 0;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.EAST)
{
rotationAngle = -90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.SOUTH)
{
rotationAngle = 180;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.WEST)
{
rotationAngle = 90;
}
yShift = 0.999d;
xRotate = 1;
}
else if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.NORTH)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.UP)
{
rotationAngle = -90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.EAST)
{
rotationAngle = -180;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.DOWN)
{
rotationAngle = 90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.WEST)
{
rotationAngle = 0;
}
zRotate = 1;
zShift = 0.999d;
}
else if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.SOUTH)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.UP)
{
rotationAngle = -90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.EAST)
{
rotationAngle = 0;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.DOWN)
{
rotationAngle = 90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.WEST)
{
rotationAngle = -180;
}
zRotate = -1;
zShift = 0.001d;
}
else if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.EAST)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.UP)
{
rotationAngle = 180;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.DOWN)
{
rotationAngle = 0;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.NORTH)
{
rotationAngle = -90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.SOUTH)
{
rotationAngle = 90;
}
yRotate = 1;
xShift = 0.001d;
}
else if (tileEntityAlchemyArray.getOrientation() == ForgeDirection.WEST)
{
if (tileEntityAlchemyArray.getRotation() == ForgeDirection.UP)
{
rotationAngle = 180;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.DOWN)
{
rotationAngle = 0;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.NORTH)
{
rotationAngle = 90;
}
else if (tileEntityAlchemyArray.getRotation() == ForgeDirection.SOUTH)
{
rotationAngle = -90;
}
yRotate = -1;
xShift = 0.999d;
}
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5d, y + 0.5d, z + 0.5d);
GL11.glScalef(1f, 1f, 1f);
// TODO: Finish making this work in this much more intelligent way than the way we did in renderSymbol
// GL11.glRotatef(rotationAngle, sideHit.offsetX, sideHit.offsetY, sideHit.offsetZ);
// GL11.glRotatef(facingCorrectionAngle, sideHit.offsetX, sideHit.offsetY, sideHit.offsetZ);
// GL11.glRotatef(90, xRotate, yRotate, zRotate);
// GL11.glTranslated(0, 0, 0.5f * zCorrection);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glTranslated(x + xShift, y + yShift, z + zShift);
GL11.glScalef(1f * scale, 1f * scale, 1f * scale);
GL11.glRotatef(rotationAngle, tileEntityAlchemyArray.getOrientation().offsetX, tileEntityAlchemyArray.getOrientation().offsetY, tileEntityAlchemyArray.getOrientation().offsetZ);
GL11.glRotatef(90, xRotate, yRotate, zRotate);
RenderUtils.renderQuad(glyph.getTexture());
GL11.glPopMatrix();
GL11.glDepthMask(true);
}
GL11.glDepthMask(true);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_CULL_FACE);
}
}
private void renderSymbol(Glyph glyph, double x, double y, double z, ForgeDirection orientation)
{
// TODO handle facing variants of glyphs
Tessellator tessellator = Tessellator.instance;
GL11.glPushMatrix();
tessellator.startDrawingQuads();
if (orientation == ForgeDirection.DOWN)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0f, 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.999d, z + glyph.getSize(), 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.999d, z, 0, 1);
tessellator.addVertexWithUV(x, y + 0.999d, z, 1, 1);
tessellator.addVertexWithUV(x, y + 0.999d, z + glyph.getSize(), 1, 0);
}
else if (orientation == ForgeDirection.UP)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0f, 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.001d, z + glyph.getSize(), 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + 0.001d, z, 0, 1);
tessellator.addVertexWithUV(x, y + 0.001d, z, 1, 1);
tessellator.addVertexWithUV(x, y + 0.001d, z + glyph.getSize(), 1, 0);
}
else if (orientation == ForgeDirection.NORTH)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f), 0f);
tessellator.addVertexWithUV(x, y + glyph.getSize(), z + 0.999d, 1, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + glyph.getSize(), z + 0.999d, 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y, z + 0.999d, 0, 1);
tessellator.addVertexWithUV(x, y, z + 0.999d, 1, 1);
}
else if (orientation == ForgeDirection.SOUTH)
{
GL11.glTranslatef(0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f), 0f);
tessellator.addVertexWithUV(x, y + glyph.getSize(), z + 0.001d, 1, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y + glyph.getSize(), z + 0.001d, 0, 0);
tessellator.addVertexWithUV(x + glyph.getSize(), y, z + 0.001d, 0, 1);
tessellator.addVertexWithUV(x, y, z + 0.001d, 1, 1);
}
else if (orientation == ForgeDirection.WEST)
{
GL11.glTranslatef(0f, 0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + 0.999d, y + glyph.getSize(), z, 0, 0);
tessellator.addVertexWithUV(x + 0.999d, y + glyph.getSize(), z + glyph.getSize(), 0, 1);
tessellator.addVertexWithUV(x + 0.999d, y, z + glyph.getSize(), 1, 1);
tessellator.addVertexWithUV(x + 0.999d, y, z, 1, 0);
}
else if (orientation == ForgeDirection.EAST)
{
GL11.glTranslatef(0f, 0.5f - (glyph.getSize() / 2f), 0.5f - (glyph.getSize() / 2f));
tessellator.addVertexWithUV(x + 0.001d, y + glyph.getSize(), z, 0, 0);
tessellator.addVertexWithUV(x + 0.001d, y + glyph.getSize(), z + glyph.getSize(), 0, 1);
tessellator.addVertexWithUV(x + 0.001d, y, z + glyph.getSize(), 1, 1);
tessellator.addVertexWithUV(x + 0.001d, y, z, 1, 0);
}
tessellator.draw();
GL11.glPopMatrix();
}
}

View file

@ -39,7 +39,7 @@ public class RenderUtils
public static void drawInWorldTransmutationOverlay(DrawBlockHighlightEvent event, ResourceLocation texture, int size, int rotation)
{
// TODO: Only render glyphs if they can be placed
// TODO: Move this to DrawHighlightEventHandler - it has no place here!
double x = event.target.blockX + 0.5F;
double y = event.target.blockY + 0.5F;
@ -63,6 +63,7 @@ public class RenderUtils
int chargeLevel = size;
ForgeDirection sideHit = ForgeDirection.getOrientation(event.target.sideHit);
TileEntity tileEntity = event.player.worldObj.getTileEntity(event.target.blockX, event.target.blockY, event.target.blockZ);
switch (sideHit)
{
case UP:
@ -153,7 +154,7 @@ public class RenderUtils
GL11.glRotatef(90, xRotate, yRotate, zRotate);
GL11.glTranslated(0, 0, 0.5f * zCorrection);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
renderQuad(texture);
renderPulsingQuad(texture, 1f);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDepthMask(true);
@ -176,4 +177,48 @@ public class RenderUtils
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
public static void renderPulsingQuad(ResourceLocation texture, float maxTransparency)
{
float pulseTransparency = getPulseValue() * maxTransparency / 3000f;
FMLClientHandler.instance().getClient().renderEngine.bindTexture(texture);
Tessellator tessellator = Tessellator.instance;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1, 1, 1, pulseTransparency);
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(1, 1, 1, pulseTransparency);
tessellator.addVertexWithUV(-0.5D, 0.5D, 0F, 0, 1);
tessellator.addVertexWithUV(0.5D, 0.5D, 0F, 1, 1);
tessellator.addVertexWithUV(0.5D, -0.5D, 0F, 1, 0);
tessellator.addVertexWithUV(-0.5D, -0.5D, 0F, 0, 0);
tessellator.draw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
private static int getPulseValue()
{
if (doInc)
{
pulse += 50;
}
else
{
pulse -= 50;
}
if (pulse == 3000)
{
doInc = false;
}
if (pulse == 0)
{
doInc = true;
}
return pulse;
}
private static int pulse = 0;
private static boolean doInc = true;
}

View file

@ -11,50 +11,174 @@ import net.minecraft.network.Packet;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityAlchemyArray extends TileEntityEE {
public class TileEntityAlchemyArray extends TileEntityEE
{
private AlchemyArray alchemyArray;
private ForgeDirection rotation;
public TileEntityAlchemyArray() {
public TileEntityAlchemyArray()
{
super();
alchemyArray = new AlchemyArray();
rotation = ForgeDirection.UNKNOWN;
}
public AlchemyArray getAlchemyArray() {
public AlchemyArray getAlchemyArray()
{
return alchemyArray;
}
public boolean addGlyphToAlchemyArray(Glyph glyph) {
public boolean addGlyphToAlchemyArray(Glyph glyph)
{
return alchemyArray.addGlyph(glyph);
}
public boolean addGlyphToAlchemyArray(Glyph glyph, int size) {
public boolean addGlyphToAlchemyArray(Glyph glyph, int size)
{
return addGlyphToAlchemyArray(new Glyph(glyph, size));
}
public ForgeDirection getRotation() {
public ForgeDirection getRotation()
{
return rotation;
}
public void setRotation(ForgeDirection rotation) {
this.rotation = rotation;
public void setRotation(int rotation, int facing)
{
if (this.orientation == ForgeDirection.UP)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.NORTH;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.EAST;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.SOUTH;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.WEST;
}
}
else if (this.orientation == ForgeDirection.DOWN)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.NORTH;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.EAST;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.SOUTH;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.WEST;
}
}
else if (this.orientation == ForgeDirection.NORTH)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.UP;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.EAST;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.DOWN;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.WEST;
}
}
else if (this.orientation == ForgeDirection.SOUTH)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.DOWN;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.EAST;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.UP;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.WEST;
}
}
else if (this.orientation == ForgeDirection.EAST)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.NORTH;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.UP;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.SOUTH;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.DOWN;
}
}
else if (this.orientation == ForgeDirection.WEST)
{
if ((rotation + facing) % 4 == 0)
{
this.rotation = ForgeDirection.NORTH;
}
else if ((rotation + facing) % 4 == 1)
{
this.rotation = ForgeDirection.DOWN;
}
else if ((rotation + facing) % 4 == 2)
{
this.rotation = ForgeDirection.SOUTH;
}
else if ((rotation + facing) % 4 == 3)
{
this.rotation = ForgeDirection.UP;
}
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox() {
public AxisAlignedBB getRenderBoundingBox()
{
// TODO: Make this glyph size and orientation sensitive
return AxisAlignedBB.getBoundingBox(xCoord - alchemyArray.getLargestGlyphSize(), yCoord - alchemyArray.getLargestGlyphSize(), zCoord - alchemyArray.getLargestGlyphSize(), xCoord + alchemyArray.getLargestGlyphSize(), yCoord + alchemyArray.getLargestGlyphSize(), zCoord + alchemyArray.getLargestGlyphSize());
}
@Override
public Packet getDescriptionPacket() {
public Packet getDescriptionPacket()
{
return PacketHandler.INSTANCE.getPacketFrom(new MessageTileEntityAlchemyArray(this));
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
NBTTagCompound alchemyArrayTagCompound = nbtTagCompound.getCompoundTag("alchemyArray");
@ -64,7 +188,8 @@ public class TileEntityAlchemyArray extends TileEntityEE {
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
NBTTagCompound alchemyArrayTagCompound = new NBTTagCompound();