diff options
author | Julian Braun <julianbraun6@gmail.com> | 2021-04-06 00:23:56 +0200 |
---|---|---|
committer | Julian Braun <julianbraun6@gmail.com> | 2021-04-06 00:23:56 +0200 |
commit | ac921e7f125b6d8f252a78c7aa666e0df74d5b1e (patch) | |
tree | fdc00310ae78dbab20fc0cd4ffc3f58742c947d4 /src/main/java/me/xmrvizzy/skyblocker/utils | |
parent | dd58bd4a7705da2c97e2bbd6a5979225e5f8245d (diff) | |
download | Skyblocker-ac921e7f125b6d8f252a78c7aa666e0df74d5b1e.tar.gz Skyblocker-ac921e7f125b6d8f252a78c7aa666e0df74d5b1e.tar.bz2 Skyblocker-ac921e7f125b6d8f252a78c7aa666e0df74d5b1e.zip |
add trivia and blaze dungeon quest
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/utils')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java | 199 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtilsLiving.java | 138 |
2 files changed, 337 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java new file mode 100644 index 00000000..f88accab --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtils.java @@ -0,0 +1,199 @@ +package me.xmrvizzy.skyblocker.utils; + +import com.mojang.blaze3d.platform.GlStateManager; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.*; +import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +public class RenderUtils { + + public static void drawFilledBox(BlockPos blockPos, float r, float g, float b, float a) { + drawFilledBox(new Box(blockPos), r, g, b, a); + } + + public static void drawFilledBox(Box box, float r, float g, float b, float a) { + gl11Setup(); + + // Fill + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(5, VertexFormats.POSITION_COLOR); + WorldRenderer.drawBox(buffer, + box.minX, box.minY, box.minZ, + box.maxX, box.maxY, box.maxZ, r, g, b, a / 2f); + tessellator.draw(); + + // Outline + buffer.begin(3, VertexFormats.POSITION_COLOR); + buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, 0f).next(); + buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, 0f).next(); + buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, 0f).next(); + buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); + tessellator.draw(); + + gl11Cleanup(); + } + + public static void drawOutlineBox(BlockPos blockPos, float r, float g, float b, float a) { + drawOutlineBox(new Box(blockPos), r, g, b, a); + } + + public static void fillGradient(MatrixStack matrix, int x1, int y1, int x2, int y2, int color1, int color2) { + float float_1 = (color1 >> 24 & 255) / 255.0F; + float float_2 = (color1 >> 16 & 255) / 255.0F; + float float_3 = (color1 >> 8 & 255) / 255.0F; + float float_4 = (color1 & 255) / 255.0F; + float float_5 = (color2 >> 24 & 255) / 255.0F; + float float_6 = (color2 >> 16 & 255) / 255.0F; + float float_7 = (color2 >> 8 & 255) / 255.0F; + float float_8 = (color2 & 255) / 255.0F; + Tessellator tessellator_1 = Tessellator.getInstance(); + BufferBuilder bufferBuilder_1 = tessellator_1.getBuffer(); + bufferBuilder_1.begin(7, VertexFormats.POSITION_COLOR); + bufferBuilder_1.vertex(x1, y1, 0).color(float_2, float_3, float_4, float_1).next(); + bufferBuilder_1.vertex(x1, y2, 0).color(float_2, float_3, float_4, float_1).next(); + bufferBuilder_1.vertex(x2, y2, 0).color(float_6, float_7, float_8, float_5).next(); + bufferBuilder_1.vertex(x2, y1, 0).color(float_6, float_7, float_8, float_5).next(); + tessellator_1.draw(); + } + + + public static void drawOutlineBox(Box box, float r, float g, float b, float a) { + gl11Setup(); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + + // Outline + buffer.begin(3, VertexFormats.POSITION_COLOR); + buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.maxY, box.minZ).color(r, g, b, a).next(); + buffer.vertex(box.minX, box.minY, box.maxZ).color(r, g, b, 0f).next(); + buffer.vertex(box.minX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.maxZ).color(r, g, b, 0f).next(); + buffer.vertex(box.maxX, box.maxY, box.maxZ).color(r, g, b, a).next(); + buffer.vertex(box.maxX, box.minY, box.minZ).color(r, g, b, 0f).next(); + buffer.vertex(box.maxX, box.maxY, box.minZ).color(r, g, b, a).next(); + tessellator.draw(); + + gl11Cleanup(); + } + + public static void drawLine(double x1, double y1, double z1, double x2, double y2, double z2, float r, float g, float b, float t) { + gl11Setup(); + GL11.glLineWidth(t); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder buffer = tessellator.getBuffer(); + buffer.begin(3, VertexFormats.POSITION_COLOR); + buffer.vertex(x1, y1, z1).color(r, g, b, 0.0F).next(); + buffer.vertex(x1, y1, z1).color(r, g, b, 1.0F).next(); + buffer.vertex(x2, y2, z2).color(r, g, b, 1.0F).next(); + tessellator.draw(); + + gl11Cleanup(); + + } + + public static void drawRect(float x, float y, float w, float h, int color, float alpha) { + float red = (float) (color >> 16 & 255) / 255.0F; + float green = (float) (color >> 8 & 255) / 255.0F; + float blue = (float) (color & 255) / 255.0F; + final Tessellator tessellator = Tessellator.getInstance(); + final BufferBuilder bufferbuilder = tessellator.getBuffer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture(); + GlStateManager.blendFuncSeparate(770, 771, 1, 0); + bufferbuilder.begin(7, VertexFormats.POSITION_COLOR); + bufferbuilder.vertex(x, h, 0.0D).color(red, green, blue, alpha).next(); + bufferbuilder.vertex(w, h, 0.0D).color(red, green, blue, alpha).next(); + bufferbuilder.vertex(w, y, 0.0D).color(red, green, blue, alpha).next(); + bufferbuilder.vertex(x, y, 0.0D).color(red, green, blue, alpha).next(); + tessellator.draw(); + GlStateManager.enableTexture(); + GlStateManager.disableBlend(); + } + + public static void offsetRender() { + Camera camera = BlockEntityRenderDispatcher.INSTANCE.camera; + Vec3d camPos = camera.getPos(); + GL11.glRotated(MathHelper.wrapDegrees(camera.getPitch()), 1, 0, 0); + GL11.glRotated(MathHelper.wrapDegrees(camera.getYaw() + 180.0), 0, 1, 0); + GL11.glTranslated(-camPos.x, -camPos.y, -camPos.z); + } + + public static void gl11Setup() { + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_BLEND); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + GL11.glLineWidth(2.5F); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_LINE_SMOOTH); + offsetRender(); + } + + public static void gl11Cleanup() { + GL11.glDisable(GL11.GL_LINE_SMOOTH); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + GL11.glPopMatrix(); + } + + + public static void DrawPolygon(double x, double y, int radius, int sides, int color) { + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + final Tessellator tessellator = Tessellator.getInstance(); + final BufferBuilder bufferbuilder = tessellator.getBuffer(); + + bufferbuilder.begin(GL11.GL_TRIANGLE_FAN, VertexFormats.POSITION); + + float alpha = (float) (color >> 24 & 255) / 255.0F; + float red = (float) (color >> 16 & 255) / 255.0F; + float green = (float) (color >> 8 & 255) / 255.0F; + float blue = (float) (color & 255) / 255.0F; + + bufferbuilder.vertex(x, y, 0).next(); + final double TWICE_PI = Math.PI * 2; + + for (int i = 0; i <= sides; i++) { + double angle = (TWICE_PI * i / sides) + Math.toRadians(180); + bufferbuilder.vertex(x + Math.sin(angle) * radius, y + Math.cos(angle) * radius, 0).next(); + } + tessellator.draw(); + + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + } +}
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtilsLiving.java b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtilsLiving.java new file mode 100644 index 00000000..a4c00499 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/RenderUtilsLiving.java @@ -0,0 +1,138 @@ +package me.xmrvizzy.skyblocker.utils; + +/* + * This file is part of the MacHack distribution (https://github.com/BleachDrinker420/bleachhack-1.14/). + * Copyright (c) 2019 Bleach. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormats; +import net.minecraft.client.render.model.json.ModelTransformation.Mode; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.enchantment.Enchantment; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL14; + +import java.awt.*; +import java.util.Map.Entry; + +public class RenderUtilsLiving { + + private static MinecraftClient mc = MinecraftClient.getInstance(); + public static void drawText(String str, double x, double y, double z, double scale) + { + drawText(str, x, y, z, scale, 0.0F, 0.0F, 0.0F); + } + public static void drawText(String str, double x, double y, double z, double scale, float red, float green, float blue) { + glSetup(x, y, z); + + GL11.glScaled(-0.025 * scale, -0.025 * scale, 0.025 * scale); + + int i = mc.textRenderer.getWidth(str) / 2; + GL11.glDisable(GL11.GL_TEXTURE_2D); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + bufferbuilder.begin(7, VertexFormats.POSITION_COLOR); + float f = mc.options.getTextBackgroundOpacity(0.25F); + bufferbuilder.vertex(-i - 1, -1, 0.0D).color(red, green, blue, f).next(); + bufferbuilder.vertex(-i - 1, 8, 0.0D).color(red, green, blue, f).next(); + bufferbuilder.vertex(i + 1, 8, 0.0D).color(red, green, blue, f).next(); + bufferbuilder.vertex(i + 1, -1, 0.0D).color(red, green, blue, f).next(); + tessellator.draw(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + + mc.textRenderer.draw(new MatrixStack(), str, -i, 0, 553648127); + mc.textRenderer.draw(new MatrixStack(), str, -i, 0, -1); + + glCleanup(); + } + + public static void drawItem(double x, double y, double z, double offX, double offY, double scale, ItemStack item) { + glSetup(x, y, z); + + GL11.glScaled(0.4 * scale, 0.4 * scale, 0); + + GL11.glTranslated(offX, offY, 0); + if (item.getItem() instanceof BlockItem) GL11.glRotatef(180F, 1F, 180F, 10F); + mc.getItemRenderer().renderItem(new ItemStack( + item.getItem()), Mode.GUI, 0, 0, new MatrixStack(), mc.getBufferBuilders().getEntityVertexConsumers()); + if (item.getItem() instanceof BlockItem) GL11.glRotatef(-180F, -1F, -180F, -10F); + GL11.glDisable(GL11.GL_LIGHTING); + + GL11.glScalef(-0.05F, -0.05F, 0); + + if (item.getCount() > 0) { + int w = mc.textRenderer.getWidth("x" + item.getCount()) / 2; + mc.textRenderer.drawWithShadow(new MatrixStack(), "x" + item.getCount(), 7 - w, 5, 0xffffff); + } + + GL11.glScalef(0.85F, 0.85F, 0.85F); + + int c = 0; + for (Entry<Enchantment, Integer> m : EnchantmentHelper.get(item).entrySet()) { + int w1 = mc.textRenderer.getWidth(I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue()) / 2; + mc.textRenderer.drawWithShadow(new MatrixStack(), + I18n.translate(m.getKey().getName(2).asString()).substring(0, 2) + m.getValue(), -4 - w1, c * 10 - 1, + m.getKey() == Enchantments.VANISHING_CURSE || m.getKey() == Enchantments.BINDING_CURSE + ? 0xff5050 : 0xffb0e0); + c--; + } + + GL11.glScalef(0.6F, 0.6F, 0.6F); + String dur = item.getMaxDamage() - item.getDamage() + ""; + int color = 0x000000; + try { + color = MathHelper.hsvToRgb(((float) (item.getMaxDamage() - item.getDamage()) / item.getMaxDamage()) / 3.0F, 1.0F, 1.0F); + } catch (Exception e) { + } + if (item.isDamageable()) mc.textRenderer.drawWithShadow(new MatrixStack(), dur, -8 - dur.length() * 3, 15, + new Color(color >> 16 & 255, color >> 8 & 255, color & 255).getRGB()); + + glCleanup(); + } + + public static void glSetup(double x, double y, double z) { + GL11.glPushMatrix(); + RenderUtils.offsetRender(); + GL11.glTranslated(x, y, z); + GL11.glNormal3f(0.0F, 1.0F, 0.0F); + GL11.glRotatef(-mc.player.yaw, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(mc.player.pitch, 1.0F, 0.0F, 0.0F); + //GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + GL11.glEnable(GL11.GL_BLEND); + GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO); + + } + + public static void glCleanup() { + //GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_BLEND); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glPopMatrix(); + } +}
\ No newline at end of file |