diff options
Diffstat (limited to 'TF2 Crates/src/main/java/tlhpoeCore')
12 files changed, 560 insertions, 0 deletions
diff --git a/TF2 Crates/src/main/java/tlhpoeCore/BasicMessageT.java b/TF2 Crates/src/main/java/tlhpoeCore/BasicMessageT.java new file mode 100755 index 0000000..a2fb5df --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/BasicMessageT.java @@ -0,0 +1,25 @@ +package tlhpoeCore;
+
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import io.netty.buffer.ByteBuf;
+import net.minecraft.entity.player.EntityPlayerMP;
+
+public abstract class BasicMessageT implements IMessage {
+ @Override
+ public abstract void fromBytes(ByteBuf buf);
+
+ @Override
+ public abstract void toBytes(ByteBuf buf);
+
+ public void sendToAll() {
+ TLHPoE.networkChannel.sendToAll(this);
+ }
+
+ public void sendTo(EntityPlayerMP player) {
+ TLHPoE.networkChannel.sendTo(this, player);
+ }
+
+ public void sendToServer() {
+ TLHPoE.networkChannel.sendToServer(this);
+ }
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/ClientProxyT.java b/TF2 Crates/src/main/java/tlhpoeCore/ClientProxyT.java new file mode 100755 index 0000000..5b9c07d --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/ClientProxyT.java @@ -0,0 +1,50 @@ +package tlhpoeCore;
+
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.network.FMLNetworkEvent.ClientConnectedToServerEvent;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.util.ChatComponentText;
+import tlhpoeCore.util.MCUtil;
+
+public class ClientProxyT extends ServerProxyT {
+ @Override
+ public void doClient() {
+ FMLCommonHandler.instance().bus().register(this);
+
+ TLHPoE.registerUpdateDetector(ReferenceT.ID, ReferenceT.NAME,
+ ReferenceT.VERSION, "0B6mhkrh-GwwwTFkyWWh5b3BiYU0");
+ }
+
+ @SubscribeEvent
+ public void connect(ClientConnectedToServerEvent event) {
+ if (!Loader.isModLoaded("VersionChecker")) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ boolean done = false;
+
+ while (!done) {
+ EntityPlayer player = MCUtil.getMC().thePlayer;
+
+ if (player != null) {
+ done = true;
+
+ player.addChatMessage(new ChatComponentText(
+ "If you want to be notified of the latest update from any of TLHPoE's mods, install the VersionChecker mod!"));
+ } else {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ Thread.currentThread().interrupt();
+ }
+ }).start();
+ }
+ }
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/ReferenceT.java b/TF2 Crates/src/main/java/tlhpoeCore/ReferenceT.java new file mode 100755 index 0000000..302afc4 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/ReferenceT.java @@ -0,0 +1,12 @@ +package tlhpoeCore;
+
+public class ReferenceT {
+ public static final String ID = "tlhpoeCore";
+ public static final String NAME = "TLHPoE Core";
+ public static final String VERSION = "1.9";
+
+ public static boolean DEOBFUSCATED = false;
+
+ public static final int DEFAULT_WIDTH = 854;
+ public static final int DEFAULT_HEIGHT = 480;
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/ScaledResolutionT.java b/TF2 Crates/src/main/java/tlhpoeCore/ScaledResolutionT.java new file mode 100755 index 0000000..deba078 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/ScaledResolutionT.java @@ -0,0 +1,18 @@ +package tlhpoeCore;
+
+import net.minecraft.client.gui.ScaledResolution;
+import tlhpoeCore.util.MCUtil;
+
+public class ScaledResolutionT extends ScaledResolution {
+ public ScaledResolutionT(int width, int height) {
+ super(MCUtil.getMC(), width, height);
+ }
+
+ public double getScaledX(double x) {
+ return (x / ReferenceT.DEFAULT_WIDTH) * getScaledWidth_double();
+ }
+
+ public double getScaledY(double y) {
+ return (y / ReferenceT.DEFAULT_HEIGHT) * getScaledHeight_double();
+ }
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/ServerProxyT.java b/TF2 Crates/src/main/java/tlhpoeCore/ServerProxyT.java new file mode 100755 index 0000000..230d0de --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/ServerProxyT.java @@ -0,0 +1,15 @@ +package tlhpoeCore;
+
+import cpw.mods.fml.relauncher.Side;
+import tlhpoeCore.network.MessagePlaySound;
+
+public class ServerProxyT {
+ public void doServer() {
+ TLHPoE.networkChannel.registerMessage(
+ MessagePlaySound.Handler.class, MessagePlaySound.class,
+ TLHPoE.getNextMessageID(), Side.CLIENT);
+ }
+
+ public void doClient() {
+ }
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/TLHPoE.java b/TF2 Crates/src/main/java/tlhpoeCore/TLHPoE.java new file mode 100755 index 0000000..1147cb9 --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/TLHPoE.java @@ -0,0 +1,81 @@ +package tlhpoeCore;
+
+import static tlhpoeCore.ReferenceT.ID;
+import static tlhpoeCore.ReferenceT.NAME;
+import static tlhpoeCore.ReferenceT.VERSION;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import cpw.mods.fml.common.Mod;
+import cpw.mods.fml.common.Mod.EventHandler;
+import cpw.mods.fml.common.Mod.Instance;
+import cpw.mods.fml.common.SidedProxy;
+import cpw.mods.fml.common.event.FMLInterModComms;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.network.NetworkRegistry;
+import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.nbt.NBTTagCompound;
+import tlhpoeCore.util.MiscUtil;
+
+@Mod(modid = ID, name = NAME, version = VERSION)
+public class TLHPoE {
+ @Instance(ID)
+ public static TLHPoE instance;
+ @SidedProxy(clientSide = ID + ".ClientProxyT",
+ serverSide = ID + ".ServerProxyT")
+ public static ServerProxyT proxy;
+
+ public static SimpleNetworkWrapper networkChannel;
+
+ private static int nextMessageID = 0;
+
+ @EventHandler
+ public void preInit(FMLPreInitializationEvent e) {
+ ReferenceT.DEOBFUSCATED = (Boolean) Launch.blackboard
+ .get("fml.deobfuscatedEnvironment");
+
+ networkChannel =
+ NetworkRegistry.INSTANCE.newSimpleChannel("TLHPoE");
+
+ proxy.doServer();
+ proxy.doClient();
+ }
+
+ public static void registerUpdateDetector(String modid, String name,
+ String modVersion, String driveID) {
+ String newVersion = null;
+
+ try {
+ newVersion = MiscUtil
+ .getURLText("https://docs.google.com/uc?authuser=0&id="
+ + driveID + "&export=download");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ if (modVersion.equals(newVersion)) {
+ return;
+ }
+
+ NBTTagCompound nbt = new NBTTagCompound();
+
+ nbt.setString("modDisplayName", name);
+ nbt.setString("oldVersion", modVersion);
+ nbt.setString("newVersion", newVersion);
+ nbt.setString("updateUrl", "http://adfoc.us/23774349240713");
+ nbt.setBoolean("isDirectLink", false);
+
+ FMLInterModComms.sendRuntimeMessage(modid, "VersionChecker",
+ "addUpdate", nbt);
+ }
+
+ public static int getNextMessageID() {
+ return nextMessageID++;
+ }
+}
\ No newline at end of file diff --git a/TF2 Crates/src/main/java/tlhpoeCore/network/MessagePlaySound.java b/TF2 Crates/src/main/java/tlhpoeCore/network/MessagePlaySound.java new file mode 100755 index 0000000..0e646fb --- /dev/null +++ b/TF2 Crates/src/main/java/tlhpoeCore/network/MessagePlaySound.java @@ -0,0 +1,43 @@ +package tlhpoeCore.network;
+
+import cpw.mods.fml.common.network.ByteBufUtils;
+import cpw.mods.fml.common.network.simpleimpl.IMessage;
+import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
+import cpw.mods.fml.common.network.simpleimpl.MessageContext;
+import io.netty.buffer.ByteBuf;
+import tlhpoeCore.BasicMessageT;
+import tlhpoeCore.util.MCUtil;
+
+public class MessagePlaySound extends BasicMessageT {
+ public String soundName;
+
+ public MessagePlaySound() {
+ this("");
+ }
+
+ public MessagePlaySound(String soundName) {
+ this.soundName = soundName;
+ }
+
+ @Override
+ public void toBytes(ByteBuf buf) {
+ ByteBufUtils.writeUTF8String(buf, soundName);
+ }
+
+ @Override
+ public void fromBytes(ByteBuf buf) {
+ soundName = ByteBufUtils.readUTF8String(buf);
+ }
+
+ public static class Handler
+ implements IMessageHandler<MessagePlaySound, IMessage> {
+ @Override
+ public IMessage onMessage(MessagePlaySound message,
+ MessageContext ctx) {
+ MCUtil.getMC().thePlayer.playSound(message.soundName, 0.25F,
+ 1F);
+
+ return null;
+ }
+ }
+}
\ No newline at end of file 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 |
