- 1,470
- 19
- 189
Мне нужно, что бы при нажатии на кнопку, выполнялся код на определённое время. Как это сделать?
Код:
public class ChangeGui {
Minecraft mc = Minecraft.getMinecraft();
protected float zLevel;
@SubscribeEvent
public void render(RenderGameOverlayEvent.Pre event) {
if (event.type == ElementType.FOOD) {
event.setCanceled(true);
}
if (event.type == ElementType.HEALTH) {
event.setCanceled(true);
}
if (event.type == ElementType.ARMOR) {
// event.setCanceled(true);
}
if (event.type == ElementType.AIR) {
event.setCanceled(true);
}
}
@SubscribeEvent
public void render(RenderGameOverlayEvent.Post event) {
Minecraft mc = Minecraft.getMinecraft();
ScaledResolution scale = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
ExtendedPlayer ep = new ExtendedPlayer(mc.thePlayer).get(mc.thePlayer);
int universalR = 20;
int hpX = scale.getScaledWidth() / 2 - 72;
int hpY = scale.getScaledHeight() - 50;
int hungerX = scale.getScaledWidth() / 2 - 25;
int hungerY = scale.getScaledHeight() - 50;
int oxygenX = scale.getScaledWidth() / 2 + 22;
int oxygenY = scale.getScaledHeight() - 50;
String temp = "Player temperature: " + String.valueOf(ep.getPlayerTemp(mc.thePlayer));
int playerTempX = scale.getScaledWidth() / 2 - 197;
int playerTempY = scale.getScaledHeight() - 9;
mc.fontRenderer.drawString(temp, playerTempX - 20, playerTempY, 0xFFFFFF);
if(KeyBinds.ShowStats.getIsKeyPressed()) {
if (!mc.thePlayer.capabilities.isCreativeMode) {
this.drawHunger(hungerX, hungerY, universalR);
this.drawHP(hpX, hpY, universalR);
this.drawOxygen(oxygenX, oxygenY, universalR);
}
}
// Debug
if (RCC.DEBUG) {
// Log.warn("Temp: " + props.getTemp());
}
}
/**
* @param xC
* @param yC
* @param r
*/
public void drawHP(double xC, double yC, int r) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
double x, y;
GL11.glColor4f(0.2f, 0.2f, 0.2f, 1);
Tessellator tess = new Tessellator();
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= 30; i++) {
x = (r * Math.sin(Math.toRadians(i * (360 / 30)))) + xC;
y = (r * Math.cos(Math.toRadians(i * (360 / 30)))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
float hp = Minecraft.getMinecraft().thePlayer.getHealth();
float maxHP = Minecraft.getMinecraft().thePlayer.getMaxHealth();
GL11.glColor4f(1f, 0f, 0f, 1);
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
GL11.glDisable(GL11.GL_CULL_FACE);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= hp; i++) {
double angle = 360 - (i * (360 / maxHP));
x = (r * Math.sin(Math.toRadians(angle))) + xC;
y = (r * Math.cos(Math.toRadians(angle))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_CULL_FACE);
this.mc.getTextureManager().bindTexture(new ResourceLocation(RCC.MODID + ":" + "textures/gui/statsHP.png"));
GL11.glColor3f(1, 1, 1);
GL11.glTranslated(0, 0, 500);
RenderUtils.drawScaledCustomSizeModalRect((int) xC - r, (int) yC - r, 0, 0, 133 + 3, 133 + 3, r * 2, r * 2,
133 * 2 - 5, 133 * 2 - 5);
GL11.glPopMatrix();
}
/**
* @param xC
* @param yC
* @param r
*/
public void drawHunger(double xC, double yC, int r) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
double x, y;
GL11.glColor4f(0.2f, 0.2f, 0.2f, 1);
Tessellator tess = new Tessellator();
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= 30; i++) {
x = (r * Math.sin(Math.toRadians(i * (360 / 30)))) + xC;
y = (r * Math.cos(Math.toRadians(i * (360 / 30)))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
float hunger = Minecraft.getMinecraft().thePlayer.getFoodStats().getFoodLevel();
float maxHunger = 20.0F;
GL11.glColor4f(1f, 0f, 0f, 1);
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
GL11.glDisable(GL11.GL_CULL_FACE);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= hunger; i++) {
double angle = 360 - (i * (360 / maxHunger));
x = (r * Math.sin(Math.toRadians(angle))) + xC;
y = (r * Math.cos(Math.toRadians(angle))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_CULL_FACE);
this.mc.getTextureManager().bindTexture(new ResourceLocation(RCC.MODID + ":" + "textures/gui/statsHunger.png"));
GL11.glColor3f(1, 1, 1);
GL11.glTranslated(0, 0, 500);
ScaledResolution scale = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int tw = scale.getScaledWidth();
int th = scale.getScaledHeight();
RenderUtils.drawScaledCustomSizeModalRect((int) xC - r, (int) yC - r, 0, 0, 133 + 3, 133 + 3, r * 2, r * 2,
133 * 2 - 5, 133 * 2 - 5);
GL11.glPopMatrix();
}
/**
* @param xC
* @param yC
* @param r
*/
public void drawOxygen(double xC, double yC, int r) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
double x, y;
GL11.glColor4f(0.2f, 0.2f, 0.2f, 1);
Tessellator tess = new Tessellator();
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= 30; i++) {
x = (r * Math.sin(Math.toRadians(i * (360 / 30)))) + xC;
y = (r * Math.cos(Math.toRadians(i * (360 / 30)))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
float oxygen = Minecraft.getMinecraft().thePlayer.getAir() / 3;
float maxOxygen = 300.0F / 3;
GL11.glColor4f(1f, 0f, 0f, 1);
tess.startDrawing(GL11.GL_TRIANGLE_FAN);
GL11.glDisable(GL11.GL_CULL_FACE);
tess.addVertex(xC, yC, 0);
for (int i = 0; i <= oxygen; i++) {
double angle = 360 - (i * (360 / maxOxygen));
x = (r * Math.sin(Math.toRadians(angle))) + xC;
y = (r * Math.cos(Math.toRadians(angle))) + yC;
tess.addVertex(x, y, 0);
}
tess.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_CULL_FACE);
this.mc.getTextureManager().bindTexture(new ResourceLocation(RCC.MODID + ":" + "textures/gui/statsOxygen.png"));
GL11.glColor3f(1, 1, 1);
GL11.glTranslated(0, 0, 500);
ScaledResolution scale = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int tw = scale.getScaledWidth();
int th = scale.getScaledHeight();
RenderUtils.drawScaledCustomSizeModalRect((int) xC - r, (int) yC - r, 0, 0, 133 + 3, 133 + 3, r * 2, r * 2,
133 * 2 - 5, 133 * 2 - 5);
GL11.glPopMatrix();
}
}