use of micdoodle8.mods.galacticraft.core.client.screen.DrawGameScreen in project Galacticraft by micdoodle8.
the class GameScreenText method render.
@Override
@SideOnly(Side.CLIENT)
public void render(int type, float ticks, float sizeX, float sizeY, IScreenManager scr) {
DrawGameScreen screen = (DrawGameScreen) scr;
frameBx = sizeX - frameA;
frameBy = sizeY - frameA;
drawBlackBackground(0.0F);
planeEquation(frameA, frameA, 0, frameA, frameBy, 0, frameA, frameBy, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE0, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE0);
planeEquation(frameBx, frameBy, 0, frameBx, frameA, 0, frameBx, frameA, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE1, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE1);
planeEquation(frameA, frameBy, 0, frameBx, frameBy, 0, frameBx, frameBy, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE2, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE2);
planeEquation(frameBx, frameA, 0, frameA, frameA, 0, frameA, frameA, 1);
GL11.glClipPlane(GL11.GL_CLIP_PLANE3, planes);
GL11.glEnable(GL11.GL_CLIP_PLANE3);
yPos = 0;
TileEntityTelemetry telemeter = TileEntityTelemetry.getNearest(screen.driver);
// Make the text to draw. To look good it's important the width and height
// of the whole text box are correctly set here.
String strName = "";
String[] str = { GCCoreUtil.translate("gui.display.nolink"), "", "", "", "" };
Render renderEntity = null;
Entity entity = null;
float Xmargin = 0;
if (telemeter != null && telemeter.clientData.length >= 3) {
if (telemeter.clientClass != null) {
if (telemeter.clientClass == screen.telemetryLastClass && (telemeter.clientClass != EntityPlayerMP.class || telemeter.clientName.equals(screen.telemetryLastName))) {
// Used cached data from last time if possible
entity = screen.telemetryLastEntity;
renderEntity = screen.telemetryLastRender;
strName = screen.telemetryLastName;
} else {
// Create an entity to render, based on class, and get its name
entity = null;
if (telemeter.clientClass == EntityPlayerMP.class) {
strName = telemeter.clientName;
entity = new EntityOtherPlayerMP(screen.driver.getWorld(), telemeter.clientGameProfile);
renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().getEntityRenderObject(entity);
} else {
try {
entity = (Entity) telemeter.clientClass.getConstructor(World.class).newInstance(screen.driver.getWorld());
} catch (Exception ex) {
}
if (entity != null) {
strName = entity.getName();
}
renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().entityRenderMap.get(telemeter.clientClass);
}
}
// Setup special visual types from data sent by Telemetry
if (entity instanceof EntityHorse) {
((EntityHorse) entity).setHorseType(telemeter.clientData[3]);
((EntityHorse) entity).setHorseVariant(telemeter.clientData[4]);
}
if (entity instanceof EntityVillager) {
((EntityVillager) entity).setProfession(telemeter.clientData[3]);
((EntityVillager) entity).setGrowingAge(telemeter.clientData[4]);
} else if (entity instanceof EntityWolf) {
((EntityWolf) entity).setCollarColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
((EntityWolf) entity).setBegging(telemeter.clientData[4] == 1);
} else if (entity instanceof EntitySheep) {
((EntitySheep) entity).setFleeceColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
((EntitySheep) entity).setSheared(telemeter.clientData[4] == 1);
} else if (entity instanceof EntityOcelot) {
((EntityOcelot) entity).setTameSkin(telemeter.clientData[3]);
} else if (entity instanceof EntitySkeleton) {
((EntitySkeleton) entity).setSkeletonType(telemeter.clientData[3]);
} else if (entity instanceof EntityZombie) {
((EntityZombie) entity).setVillager(telemeter.clientData[3] == 1);
((EntityZombie) entity).setChild(telemeter.clientData[4] == 1);
}
}
if (entity instanceof ITelemetry) {
((ITelemetry) entity).receiveData(telemeter.clientData, str);
} else if (entity instanceof EntityLivingBase) {
// Living entity:
// data0 = time to show red damage
// data1 = health in half-hearts
// data2 = pulse
// data3 = hunger (for player); horsetype (for horse)
// data4 = oxygen (for player); horsevariant (for horse)
str[0] = telemeter.clientData[0] > 0 ? GCCoreUtil.translate("gui.player.ouch") : "";
if (telemeter.clientData[1] >= 0) {
str[1] = GCCoreUtil.translate("gui.player.health") + ": " + telemeter.clientData[1] + "%";
} else {
str[1] = "";
}
str[2] = "" + telemeter.clientData[2] + " " + GCCoreUtil.translate("gui.player.bpm");
if (telemeter.clientData[3] > -1) {
str[3] = GCCoreUtil.translate("gui.player.food") + ": " + telemeter.clientData[3] + "%";
}
if (telemeter.clientData[4] > -1) {
int oxygen = telemeter.clientData[4];
oxygen = (oxygen % 4096) + (oxygen / 4096);
if (oxygen == 180 || oxygen == 90) {
str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": OK";
} else {
str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": " + this.makeOxygenString(oxygen) + GCCoreUtil.translate("gui.seconds");
}
}
} else // TODO can add more here, e.g. position data?
if (telemeter.clientData[2] >= 0) {
str[2] = makeSpeedString(telemeter.clientData[2]);
}
} else {
// Default - draw a simple time display just to show the Display Screen is working
World w1 = screen.driver.getWorld();
int time1 = w1 != null ? (int) ((w1.getWorldTime() + 6000L) % 24000L) : 0;
str[2] = makeTimeString(time1 * 360);
}
int textWidthPixels = 155;
// 1 lines
int textHeightPixels = 60;
if (str[3].isEmpty()) {
textHeightPixels -= 10;
}
if (str[4].isEmpty()) {
textHeightPixels -= 10;
}
// First pass - approximate border size
float borders = frameA * 2 + 0.05F * Math.min(sizeX, sizeY);
float scaleXTest = (sizeX - borders) / textWidthPixels;
float scaleYTest = (sizeY - borders) / textHeightPixels;
float scale = sizeX;
if (scaleYTest < scaleXTest) {
scale = sizeY;
}
// Second pass - the border size may be more accurate now
borders = frameA * 2 + 0.05F * scale;
scaleXTest = (sizeX - borders) / textWidthPixels;
scaleYTest = (sizeY - borders) / textHeightPixels;
scale = sizeX;
float scaleText = scaleXTest;
if (scaleYTest < scaleXTest) {
scale = sizeY;
scaleText = scaleYTest;
}
// Centre the text in the display
float border = frameA + 0.025F * scale;
if (entity != null && renderEntity != null) {
Xmargin = (sizeX - borders) / 2;
}
float Xoffset = (sizeX - borders - textWidthPixels * scaleText) / 2 + Xmargin;
float Yoffset = (sizeY - borders - textHeightPixels * scaleText) / 2 + scaleText;
GL11.glTranslatef(border + Xoffset, border + Yoffset, 0.0F);
GL11.glScalef(scaleText, scaleText, 1.0F);
// Actually draw the text
int whiteColour = ColorUtil.to32BitColor(255, 240, 216, 255);
drawText(strName, whiteColour);
drawText(str[0], whiteColour);
drawText(str[1], whiteColour);
drawText(str[2], whiteColour);
drawText(str[3], whiteColour);
drawText(str[4], whiteColour);
// If there is an entity to render, draw it on the left of the text
if (renderEntity != null && entity != null) {
GL11.glTranslatef(-Xmargin / 2 / scaleText, textHeightPixels / 2 + (-Yoffset + (sizeY - borders) / 2) / scaleText, -0.0005F);
float scalefactor = 38F / (float) Math.pow(Math.max(entity.height, entity.width), 0.65);
GL11.glScalef(scalefactor, scalefactor, 0.0015F);
GL11.glRotatef(180F, 0, 0, 1);
GL11.glRotatef(180F, 0, 1, 0);
if (entity instanceof ITelemetry) {
((ITelemetry) entity).adjustDisplay(telemeter.clientData);
}
RenderPlayerGC.flagThermalOverride = true;
if (entity instanceof EntityLivingBase && renderEntity instanceof RendererLivingEntity && renderModelMethod != null) {
this.renderLiving((EntityLivingBase) entity, (RendererLivingEntity) renderEntity, ticks % 1F);
} else {
renderEntity.doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
}
RenderPlayerGC.flagThermalOverride = false;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
// TODO Cross-dimensional tracking (i.e. old entity setDead, new entity created)
// TODO Deal with text off screen (including where localizations longer than English)
screen.telemetryLastClass = (telemeter == null) ? null : telemeter.clientClass;
screen.telemetryLastEntity = entity;
screen.telemetryLastRender = renderEntity;
screen.telemetryLastName = strName;
GL11.glDisable(GL11.GL_CLIP_PLANE3);
GL11.glDisable(GL11.GL_CLIP_PLANE2);
GL11.glDisable(GL11.GL_CLIP_PLANE1);
GL11.glDisable(GL11.GL_CLIP_PLANE0);
}
use of micdoodle8.mods.galacticraft.core.client.screen.DrawGameScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method onLoad.
@Override
public void onLoad() {
if (this.worldObj.isRemote) {
this.clientOnLoad();
this.screen = new DrawGameScreen(1.0F, 1.0F, this);
}
}
use of micdoodle8.mods.galacticraft.core.client.screen.DrawGameScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method checkWholeScreen.
/**
* After figuring out the screen edges (overall screen dimensions)
* check that the screen is a whole A x B rectangle with no tiles missing
* <p>
* If it is whole, set all tiles in the screen to match this screen type
*
* @param up Number of blocks the screen edge is away from this in the up direction
* @param down Number of blocks the screen edge is away from this in the down direction
* @param left Number of blocks the screen edge is away from this in the left direction
* @param right Number of blocks the screen edge is away from this in the right direction
* @return True if the screen was whole
*/
private boolean checkWholeScreen(int up, int down, int left, int right) {
if (up + down + left + right == 0 || up < 0 || down < 0 || left < 0 || right < 0) {
this.doneClientUpdate = true;
this.resetToSingle();
return true;
}
// System.out.println("Checking screen size at "+this.getPos().getX()+","+this.getPos().getZ()+": Up "+up+" Dn "+down+" Lf "+left+" Rg "+right);
boolean screenWhole = true;
boolean existingScreen = false;
int barrierUp = up;
int barrierDown = down;
int barrierLeft = left;
int barrierRight = right;
int meta = this.getBlockMetadata() & 7;
BlockVec3 vec = new BlockVec3(this);
ArrayList<TileEntityScreen> screenList = new ArrayList<TileEntityScreen>();
// int side = this.getRight(meta);
EnumFacing side = getFront().rotateY();
for (int x = -left; x <= right; x++) {
for (int z = -up; z <= down; z++) {
BlockVec3 newVec = vec.clone().modifyPositionFromSide(side, x).modifyPositionFromSide(EnumFacing.DOWN, z);
TileEntity tile = newVec.getTileEntity(this.worldObj);
if (tile instanceof TileEntityScreen && tile.getBlockMetadata() == meta && !tile.isInvalid()) {
TileEntityScreen screenTile = (TileEntityScreen) tile;
screenList.add(screenTile);
if (screenTile.isMultiscreen) {
if (screenTile.connectionsUp > z + up) {
barrierUp = -z - 1;
existingScreen = true;
}
if (screenTile.connectionsDown > down - z) {
barrierDown = z - 1;
existingScreen = true;
}
if (screenTile.connectionsLeft > x + left) {
barrierLeft = -x - 1;
existingScreen = true;
}
if (screenTile.connectionsRight > right - x) {
barrierRight = x - 1;
existingScreen = true;
}
}
} else {
screenWhole = false;
}
}
}
if (!screenWhole) {
for (TileEntityScreen scr : screenList) {
scr.resetToSingle();
}
return false;
}
if (existingScreen) {
return this.checkWholeScreen(barrierUp, barrierDown, barrierLeft, barrierRight);
}
DrawGameScreen newScreen = null;
boolean serverside = true;
TileEntity bottomLeft = vec.clone().modifyPositionFromSide(side, -left).modifyPositionFromSide(EnumFacing.DOWN, down).getTileEntity(this.worldObj);
if (this.worldObj.isRemote) {
if (// It always will be if reached this far
bottomLeft instanceof TileEntityScreen) {
newScreen = ((TileEntityScreen) bottomLeft).screen;
if (!newScreen.check(1.0F + left + right, 1.0F + up + down)) {
newScreen = new DrawGameScreen(1.0F + left + right, 1.0F + up + down, bottomLeft);
}
}
serverside = false;
}
Iterator<TileEntityScreen> it = screenList.iterator();
for (int x = -left; x <= right; x++) {
for (int z = -up; z <= down; z++) {
TileEntityScreen screenTile = it.next();
screenTile.screenOffsetx = x + left;
screenTile.screenOffsetz = z + up;
screenTile.screen = newScreen;
screenTile.connectionsLeft = x + left;
screenTile.connectionsRight = right - x;
screenTile.connectionsUp = z + up;
screenTile.connectionsDown = down - z;
screenTile.isMultiscreen = true;
screenTile.refreshOnUpdate = false;
if (serverside) {
screenTile.imageType = this.imageType;
screenTile.markDirty();
screenTile.updateAllInDimension();
}
screenTile.refreshConnections(false);
}
}
this.connectionsUp = up;
this.connectionsDown = down;
this.connectionsLeft = left;
this.connectionsRight = right;
return true;
}
use of micdoodle8.mods.galacticraft.core.client.screen.DrawGameScreen in project Galacticraft by micdoodle8.
the class TileEntityScreen method resetToSingle.
/**
* Reset the screen to a 1x1 size, not part of a 'multi-screen'
*/
public void resetToSingle() {
this.screenOffsetx = 0;
this.screenOffsetz = 0;
this.connectionsUp = 0;
this.connectionsDown = 0;
this.connectionsLeft = 0;
this.connectionsRight = 0;
this.isMultiscreen = false;
// this.connectedDown = this.connectedLeft = this.connectedRight = this.connectedUp = false;
this.setConnectedLeft(false);
this.setConnectedRight(false);
this.setConnectedUp(false);
this.setConnectedDown(false);
this.refreshOnUpdate = false;
this.markDirty();
if (this.worldObj.isRemote) {
this.screen = new DrawGameScreen(1.0F, 1.0F, this);
} else {
this.updateAllInDimension();
}
}
Aggregations