From a11c98c6cad501e081837ec8fa2e323edaeb1ca3 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 24 May 2018 15:52:43 -0400 Subject: Initial commit --- .../src/main/java/tlhpoeCore/util/MCUtil.java | 82 +++++++++++++++++++ .../src/main/java/tlhpoeCore/util/MathUtil.java | 35 ++++++++ .../src/main/java/tlhpoeCore/util/MiscUtil.java | 94 ++++++++++++++++++++++ .../src/main/java/tlhpoeCore/util/RenderUtil.java | 43 ++++++++++ .../src/main/java/tlhpoeCore/util/WorldUtil.java | 62 ++++++++++++++ 5 files changed, 316 insertions(+) create mode 100755 TF2 Crates/src/main/java/tlhpoeCore/util/MCUtil.java create mode 100755 TF2 Crates/src/main/java/tlhpoeCore/util/MathUtil.java create mode 100755 TF2 Crates/src/main/java/tlhpoeCore/util/MiscUtil.java create mode 100755 TF2 Crates/src/main/java/tlhpoeCore/util/RenderUtil.java create mode 100755 TF2 Crates/src/main/java/tlhpoeCore/util/WorldUtil.java (limited to 'TF2 Crates/src/main/java/tlhpoeCore/util') diff --git a/TF2 Crates/src/main/java/tlhpoeCore/util/MCUtil.java b/TF2 Crates/src/main/java/tlhpoeCore/util/MCUtil.java new file mode 100755 index 0000000..01c3b2d --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/util/MCUtil.java @@ -0,0 +1,82 @@ +package tlhpoeCore.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import tlhpoeCore.ReferenceT; + +public class MCUtil { + public static Minecraft getMC() { + return Minecraft.getMinecraft(); + } + + public static Item getRandomItemOrBlock() { + Item i = null; + + int length = Item.itemRegistry.getKeys().toArray().length; + + Object select = + Item.itemRegistry.getObjectById(MathUtil.nextInt(length)); + + if (select != null && select instanceof Item) { + i = (Item) select; + } else { + return getRandomItemOrBlock(); + } + + return i; + } + + public static Item getRandomItem() { + Item i = null; + + int length = Item.itemRegistry.getKeys().toArray().length; + + Object select = + Item.itemRegistry.getObjectById(MathUtil.nextInt(length)); + + if (select != null && select instanceof Item + && !(select instanceof ItemBlock)) { + i = (Item) select; + } else { + return getRandomItem(); + } + + return i; + } + + public static Item getRandomBlock() { + Item i = null; + + int length = Item.itemRegistry.getKeys().toArray().length; + + Object select = + Item.itemRegistry.getObjectById(MathUtil.nextInt(length)); + + if (select != null && select instanceof ItemBlock) { + i = (Item) select; + } else { + return getRandomBlock(); + } + + return i; + } + + public static NBTTagCompound + getPlayerNBTCompound(EntityPlayer player) { + NBTTagCompound nbt = player.getEntityData(); + + if (nbt.getCompoundTag(ReferenceT.NAME) == null) { + nbt.setTag(ReferenceT.NAME, new NBTTagCompound()); + } + + return nbt.getCompoundTag(ReferenceT.NAME); + } + + public static ResourceLocation newResource(String url) { + return new ResourceLocation(url); + } +} \ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/util/MathUtil.java b/TF2 Crates/src/main/java/tlhpoeCore/util/MathUtil.java new file mode 100755 index 0000000..d99a147 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/util/MathUtil.java @@ -0,0 +1,35 @@ +package tlhpoeCore.util; + +import java.util.Random; + +public class MathUtil { + private static final Random RANDOM = new Random(); + + public static int nextInt(int n) { + return RANDOM.nextInt(n); + } + + public static double nextDouble() { + return RANDOM.nextDouble(); + } + + public static int getRandomIntegerBetween(Random r, int min, int max) { + return r.nextInt(max - min + 1) + min; + } + + public static int getRandomIntegerBetween(int min, int max) { + return nextInt(max - min + 1) + min; + } + + public static boolean getChance(Random r, int chance, int range) { + return chance >= range ? true : r.nextInt(range - 1) <= chance - 1; + } + + public static boolean getChance(int chance, int range) { + return chance >= range ? true : nextInt(range - 1) <= chance - 1; + } + + public static Random getRandom() { + return RANDOM; + } +} \ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/util/MiscUtil.java b/TF2 Crates/src/main/java/tlhpoeCore/util/MiscUtil.java new file mode 100755 index 0000000..f34c996 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/util/MiscUtil.java @@ -0,0 +1,94 @@ +package tlhpoeCore.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; + +public class MiscUtil { + public static Field getField(String fieldName, Class clazz) { + Field field = null; + + try { + field = clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + return field; + } + + public static Object getFieldValue(String fieldName, Class clazz, + Object instance) { + Field field = getField(fieldName, clazz); + makePublic(field); + + try { + return field.get(instance); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return null; + } + + public static void replaceField(String fieldName, Class clazz, + Object newValue, Object instance) { + Field field = getField(fieldName, clazz); + + if (field != null) { + makePublic(field); + + try { + field.set(instance, newValue); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + + private static void makePublic(Field field) { + field.setAccessible(true); + + Field modField = null; + + try { + modField = Field.class.getDeclaredField("modifiers"); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + modField.setAccessible(true); + + try { + modField.setInt(field, field.getModifiers() & ~Modifier.FINAL); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + public static String getURLText(String url) + throws MalformedURLException, IOException { + BufferedReader versionFile = new BufferedReader( + new InputStreamReader(new URL(url).openStream())); + + String s = versionFile.readLine(); + + versionFile.close(); + + return s; + } +} \ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/util/RenderUtil.java b/TF2 Crates/src/main/java/tlhpoeCore/util/RenderUtil.java new file mode 100755 index 0000000..824acf9 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/util/RenderUtil.java @@ -0,0 +1,43 @@ +package tlhpoeCore.util; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; + +public class RenderUtil { + public static void drawString(String msg, int x, int y, int color) { + MCUtil.getMC().fontRenderer.drawString(msg, x, y, color); + } + + public static void drawOutlinedString(String msg, int x, int y, + int color, int outlineColor) { + Minecraft mc = MCUtil.getMC(); + + mc.fontRenderer.drawString(msg, x - 1, y, outlineColor); + mc.fontRenderer.drawString(msg, x + 1, y, outlineColor); + mc.fontRenderer.drawString(msg, x, y - 1, outlineColor); + mc.fontRenderer.drawString(msg, x, y + 1, outlineColor); + + drawString(msg, x, y, color); + } + + public static void drawTexturedQuad(int x, int y, int width, + int height, int u, int v, int uSize, int vSize, int texSizeX, + int texSizeY, float zLevel) { + float uFact = 1f / texSizeX; + float vFact = 1f / texSizeY; + + int uEnd = u + uSize; + int vEnd = v + vSize; + + Tessellator t = Tessellator.instance; + + t.startDrawingQuads(); + t.addVertexWithUV(x, y + height, zLevel, u * uFact, vEnd * vFact); + t.addVertexWithUV(x + width, y + height, zLevel, uEnd * uFact, + vEnd * vFact); + t.addVertexWithUV(x + width, y, zLevel, uEnd * uFact, v * vFact); + t.addVertexWithUV(x, y, zLevel, u * uFact, v * vFact); + + t.draw(); + } +} \ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/util/WorldUtil.java b/TF2 Crates/src/main/java/tlhpoeCore/util/WorldUtil.java new file mode 100755 index 0000000..1aa46ab --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/util/WorldUtil.java @@ -0,0 +1,62 @@ +package tlhpoeCore.util; + +import net.minecraft.block.Block; +import net.minecraft.world.World; + +public class WorldUtil { + public static int getTopBlock(World world, int x, int z) { + for (int y = 0; y < 256; y++) { + if (world.canBlockSeeTheSky(x, y, z)) { + return y; + } + } + + return -1; + } + + public static int getTopBlockOfType(World world, int x, int z, + Block block) { + for (int y = 0; y < 256; y++) { + if (world.getBlock(x, 256 - y, z) == block) { + return 256 - y; + } + } + + return -1; + } + + public static void fillCircle(World world, double x, double y, + double z, int radius, Block block) { + world.setBlock((int) x, (int) y, (int) z, block); + + world.setBlock((int) x + 1, (int) y, (int) z, block); + world.setBlock((int) x - 1, (int) y, (int) z, block); + + world.setBlock((int) x, (int) y, (int) z + 1, block); + world.setBlock((int) x, (int) y, (int) z - 1, block); + + x += 0.5; + y += 0.5; + z += 0.5; + + while (radius != 0) { + for (int i = 0; i < 360; i++) { + world.setBlock((int) (x + radius * Math.cos(i)), (int) y, + (int) (z + radius * Math.sin(i)), block); + } + + radius--; + } + } + + public static void fillRect(World world, Block filler, int x, int y, + int z, int width, int length, int height) { + for (int i = 0; i < width; i++) { + for (int j = 0; j < length; j++) { + for (int k = 0; k < height; k++) { + world.setBlock(x + i, y + k, z + j, filler); + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3