Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.net.URL;
- import java.util.*;
- import java.util.logging.Level;
- import net.minecraft.client.Minecraft;
- public class mod_startingInventory extends BaseMod
- {
- @MLProp(info="Set to true to allow checking for mod updates, false to disable")
- public static boolean allowUpdateCheck = true;
- @MLProp(info="The length of time in game time ticks (1/20th of a second) that items are allowed to spawn in a fresh world. If you are on a slower machine and are having trouble with items not spawning, try setting this a little higher\n\n**ONLY EDIT WHAT IS BELOW THIS**")
- public static int tickWindow = 100;
- private boolean checkUpdate;
- boolean canGiveItems;
- String fileName;
- File mcdir;
- File file;
- private Scanner scan;
- private List list;
- public mod_startingInventory()
- {
- fileName = "startingInventory";
- mcdir = Minecraft.getMinecraftDir();
- file = new File(mcdir, (new StringBuilder()).append("/mods/daftpvf/").append(fileName).append(".txt").toString());
- list = new ArrayList();
- list.clear();
- if(!file.exists() || scan == null)
- {
- createFile();
- }
- readItems();
- checkUpdate = allowUpdateCheck;
- }
- @Override
- public String getVersion()
- {
- return "1.3.2.b modified by bspkrs";
- }
- @Override
- public void load()
- {
- if(!isCurrentVersion(ModLoader.getMinecraftInstance()))
- ModLoader.getLogger().log(Level.INFO, "Your version of StartingInventory is out of date! Visit http://www.minecraftforum.net/topic/1009577- for the latest version.");
- }
- @Override
- public boolean onTickInGame(float f, Minecraft mc)
- {
- if(canGiveItems && mc.isSingleplayer() && isFreshWorld(mc) && isPlayerInventoryEmpty(mc.thePlayer))
- addItems();
- canGiveItems = false;
- if(checkUpdate)
- {
- if(!isCurrentVersion(mc))
- {
- mc.thePlayer.addChatMessage("\247cYour version of StartingInventory is out of date!");
- mc.thePlayer.addChatMessage("\247cVisit http://www.minecraftforum.net/topic/1009577- for the latest version.");
- }
- checkUpdate = false;
- }
- return false;
- }
- @Override
- public void clientConnect(NetClientHandler nch)
- {
- ModLoader.setInGameHook(this, true, true);
- canGiveItems = true;
- }
- private boolean isCurrentVersion(Minecraft minecraft)
- {
- try
- {
- String[] version = loadTextFromURL(new URL("https://dl.dropbox.com/u/20748481/Minecraft/1.3.1/startingInventory.version"));
- return version[0].equalsIgnoreCase(getVersion());
- }
- catch(Throwable e)
- {
- ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
- return true;
- }
- }
- private String[] loadTextFromURL(URL url)
- {
- ArrayList arraylist = new ArrayList();
- Scanner scanner = null;
- try
- {
- scanner = new Scanner(url.openStream(), "UTF-8");
- }
- catch(Throwable e) {
- ModLoader.getLogger().log(Level.WARNING, "Error getting current version info: " + e.getStackTrace());
- return new String[] {""};
- }
- while(scanner.hasNextLine())
- {
- arraylist.add(scanner.nextLine());
- }
- scanner.close();
- return (String[])arraylist.toArray(new String[arraylist.size()]);
- }
- public boolean isFreshWorld(Minecraft mc)
- {
- try
- {
- return (int)mc.theWorld.worldInfo.getWorldTime() < tickWindow;
- }
- catch(Exception e)
- {
- return false;
- }
- }
- public boolean isPlayerInventoryEmpty(EntityClientPlayerMP player)
- {
- try
- {
- for(int i = 0; i < player.inventory.mainInventory.length; i++)
- if(player.inventory.mainInventory[i] != null)
- return false;
- return true;
- }
- catch(Exception e)
- {
- return false;
- }
- }
- public void addItems()
- {
- for(int i = 0; i < list.size(); i++)
- {
- addItem((String)list.get(i));
- }
- }
- private void addItem(String s)
- {
- int j = 1;
- int k = 0;
- int l = s.indexOf(',');
- int i1 = s.indexOf(',', l + 1);
- int i;
- if(l != -1)
- {
- i = parseInt(s.substring(0, l));
- if(i1 != -1)
- {
- j = parseInt(s.substring(l + 1, i1));
- k = parseInt(s.substring(i1 + 1));
- } else
- {
- j = parseInt(s.substring(l + 1));
- }
- } else
- {
- i = parseInt(s);
- }
- if(Item.itemsList[i] == null)
- {
- return;
- } else
- {
- Minecraft mc = ModLoader.getMinecraftInstance();
- //ModLoader.getMinecraftInstance().thePlayer.inventory.addItemStackToInventory(new ItemStack(i, j, k));
- mc.getIntegratedServer().executeCommand("give " + mc.thePlayer.username + " " + i + " " + j + " " + k);
- return;
- }
- }
- public void readItems()
- {
- if(scan != null)
- {
- for(; scan.hasNextLine(); list.add(scan.nextLine())) { }
- }
- scan.close();
- }
- public int parseInt(String s)
- {
- try
- {
- return Integer.parseInt(s.trim());
- }
- catch(NumberFormatException numberformatexception)
- {
- return 0;
- }
- }
- public void createFile()
- {
- File file1 = new File(mcdir, "/mods/daftpvf/");
- if(!file1.exists() && file1.mkdir())
- {
- file = new File(file1, (new StringBuilder()).append(fileName).append(".txt").toString());
- }
- else
- {
- file = new File(file1, (new StringBuilder()).append(fileName).append(".txt").toString());
- }
- try
- {
- file.createNewFile();
- scan = new Scanner(file);
- }
- catch(Exception exception) { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment