diff --git a/forge/.gitignore b/forge/.gitignore index f6406060eb..f10ab5531c 100644 --- a/forge/.gitignore +++ b/forge/.gitignore @@ -1,4 +1,4 @@ -/*.zip /fml/ /logs/ /*.pyc +/forge-*/ diff --git a/forge/build.py b/forge/build.py new file mode 100644 index 0000000000..a0c4e5b261 --- /dev/null +++ b/forge/build.py @@ -0,0 +1,57 @@ +import os, os.path, sys +import shutil, fnmatch +import logging + +forge_dir = os.path.dirname(os.path.abspath(__file__)) +mcp_dir = os.path.abspath('..') +src_dir = os.path.join(mcp_dir, 'src') + +sys.path.append(mcp_dir) +from runtime.recompile import recompile + +from forge import copytree, reset_logger, load_version, inject_version + +def main(): + build_num = 0 + if len(sys.argv) > 1: + try: + build_num = int(sys.argv[1]) + except: + pass + sys.exit(build(build_num)) + +def build(build_num=0): + version = load_version(build_num) + print '=================================== Build %d.%d.%d.%d Start =================================' % (version['major'], version['minor'], version['revision'], version['build']) + + if os.path.isdir(src_dir): + shutil.rmtree(src_dir) + inject_version(os.path.join(forge_dir, 'forge_common', 'net', 'minecraft', 'src', 'forge', 'ForgeHooks.java'), build_num) + + print 'src_work -> src' + copytree(os.path.join(mcp_dir, 'src_work'), src_dir) + print '\nforge_client -> minecraft' + copytree(os.path.join(forge_dir, 'forge_client', 'src'), os.path.join(src_dir, 'minecraft'), -1) + print '\nforge_server -> minecraft_server' + copytree(os.path.join(forge_dir, 'forge_server', 'src'), os.path.join(src_dir, 'minecraft_server'), -1) + print '\nforge_common -> minecraft' + copytree(os.path.join(forge_dir, 'forge_common'), os.path.join(src_dir, 'minecraft'), -1) + print '\nforge_common -> minecraft_server' + copytree(os.path.join(forge_dir, 'forge_common'), os.path.join(src_dir, 'minecraft_server'), -1) + print + + error_level = 0 + try: + os.chdir(mcp_dir) + recompile(None) + reset_logger() + os.chdir(forge_dir) + except SystemExit, e: + print 'Decompile Exception: %d ' % e.code + error_level = e.code + + print '=================================== Build Finished %d =================================' % error_level + return error_level + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/forge/download_fernflower.py b/forge/download_fernflower.py deleted file mode 100644 index c10e08fd8c..0000000000 --- a/forge/download_fernflower.py +++ /dev/null @@ -1,10 +0,0 @@ -import urllib -import zipfile - -if __name__ == '__main__': - try: - urllib.urlretrieve("http://goo.gl/PnJHp", './fernflower.zip') - zf = zipfile.ZipFile('fernflower.zip') - zf.extract('fernflower.jar', '../runtime/bin') - except: - print "Downloading Fernflower failed download manually from http://goo.gl/PnJHp" \ No newline at end of file diff --git a/forge/fml-src-1.0.0.45.zip b/forge/fml-src-1.0.0.45.zip new file mode 100644 index 0000000000..087df171e8 Binary files /dev/null and b/forge/fml-src-1.0.0.45.zip differ diff --git a/forge/forge.py b/forge/forge.py new file mode 100644 index 0000000000..590d76bdb1 --- /dev/null +++ b/forge/forge.py @@ -0,0 +1,187 @@ +import os, os.path, sys +import urllib, zipfile +import shutil, glob, fnmatch +import subprocess, logging, re + +forge_dir = os.path.dirname(os.path.abspath(__file__)) +mcp_dir = os.path.abspath('..') +src_dir = os.path.join(mcp_dir, 'src') + +sys.path.append(mcp_dir) +from runtime.pylibs.normlines import normaliselines +from runtime.commands import cmdsplit + +def apply_patches(patch_dir, target_dir): + temp = os.path.abspath('temp.patch') + cmd = cmdsplit('patch -p2 -i "%s" ' % temp) + display = True + + if os.name == 'nt': + applydiff = os.path.abspath(os.path.join(mcp_dir, 'runtime', 'bin', 'applydiff.exe')) + cmd = cmdsplit('"%s" -uf -p2 -i "%s"' % (applydiff, temp)) + display = False + + for path, _, filelist in os.walk(patch_dir, followlinks=True): + for cur_file in fnmatch.filter(filelist, '*.patch'): + patch_file = os.path.normpath(os.path.join(patch_dir, path[len(patch_dir)+1:], cur_file)) + if display: + print 'patching file %s' % os.path.join(path[len(patch_dir)+1:], cur_file) + normaliselines(patch_file, temp) + process = subprocess.Popen(cmd, cwd=target_dir, bufsize=-1) + process.communicate() + + if os.path.isfile(temp): + os.remove(temp) + +#Taken from: http://stackoverflow.com/questions/7545299/distutil-shutil-copytree +def _mkdir(newdir): + """works the way a good mkdir should :) + - already exists, silently complete + - regular file in the way, raise an exception + - parent directory(ies) does not exist, make them as well + """ + if os.path.isdir(newdir): + pass + elif os.path.isfile(newdir): + raise OSError("a file with the same name as the desired " \ + "dir, '%s', already exists." % newdir) + else: + head, tail = os.path.split(newdir) + if head and not os.path.isdir(head): + _mkdir(head) + #print "_mkdir %s" % repr(newdir) + if tail: + os.mkdir(newdir) + +#Taken from: http://stackoverflow.com/questions/7545299/distutil-shutil-copytree +def copytree(src, dst, verbose=0, symlinks=False): + """Recursively copy a directory tree using copy2(). + + The destination directory must not already exist. + If exception(s) occur, an Error is raised with a list of reasons. + + If the optional symlinks flag is true, symbolic links in the + source tree result in symbolic links in the destination tree; if + it is false, the contents of the files pointed to by symbolic + links are copied. + + XXX Consider this example code rather than the ultimate tool. + + """ + + if verbose == -1: + verbose = len(os.path.abspath(dst)) - 1 + names = os.listdir(src) + # os.makedirs(dst) + _mkdir(dst) # XXX + errors = [] + for name in names: + srcname = os.path.join(src, name) + dstname = os.path.join(dst, name) + try: + if symlinks and os.path.islink(srcname): + linkto = os.readlink(srcname) + os.symlink(linkto, dstname) + elif os.path.isdir(srcname): + copytree(srcname, dstname, verbose, symlinks) + else: + shutil.copy2(srcname, dstname) + if verbose > 0: + print os.path.abspath(srcname)[verbose:] + # XXX What about devices, sockets etc.? + except (IOError, os.error), why: + errors.append((srcname, dstname, str(why))) + # catch the Error from the recursive copytree so that we can + # continue with other files + except Exception, err: + errors.extend(err.args[0]) + try: + shutil.copystat(src, dst) + except WindowsError: + # can't copy file access times on Windows + pass + +def reset_logger(): + log = logging.getLogger() + while len(log.handlers) > 0: + log.removeHandler(log.handlers[0]) + +def download_ff(mcp_path): + bin_path = os.path.normpath(os.path.join(mcp_path, 'runtime', 'bin')) + ff_path = os.path.normpath(os.path.join(bin_path, 'fernflower.jar')) + + if os.path.isfile(ff_path): + return True + + try: + urllib.urlretrieve("http://goo.gl/PnJHp", 'fernflower.zip') + zf = zipfile.ZipFile('fernflower.zip') + zf.extract('fernflower.jar', bin_path) + zf.close() + os.remove('fernflower.zip') + print "Downloaded Fernflower successfully" + return True + except: + print "Downloading Fernflower failed download manually from http://goo.gl/PnJHp" + return False + +version_reg = re.compile(r'(([a-z]+)Version[\s]+=[\s]+)(\d+);') +def load_version(build=0): + info = {'major' : -1, + 'minor' : -1, + 'revision' : -1, + 'build' : -1 + } + hook_file = os.path.join(forge_dir, 'forge_common/net/minecraft/src/forge/ForgeHooks.java'.replace('/', os.sep)) + with open(hook_file, 'r') as fh: + buf = fh.read() + + def proc(match): + try: + info[match.group(2)] = int(match.group(3)) + except: + pass + return match.group(0) + + buf = version_reg.sub(proc, buf) + info['build'] = build + return info + +def inject_version(src_file, build=0): + version = load_version(build) + + tmp_file = src_file + '.tmp' + with open(src_file, 'r') as fh: + buf = fh.read() + + def mapname(match): + try: + return '%s%s;' % (match.group(1), version[match.group(2)]) + except KeyError: + pass + return match.group(0) + + buf = version_reg.sub(mapname, buf) + + with open(tmp_file, 'w') as fh: + fh.write(buf) + shutil.move(tmp_file, src_file) + +def zip_folder(path, key, zip): + files = os.listdir(path) + for file in files: + file_path = os.path.join(path, file) + file_key = os.path.join(key, file) + if os.path.isdir(file_path): + zip_folder(file_path, file_key, zip) + else: + print file_key + zip.write(file_path, file_key) + +def zip_create(path, key, zip_name): + zip = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED) + if os.path.isdir(path): + zip_folder(path, key, zip) + else: + zip.write(path, key) + zip.close() \ No newline at end of file diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index 60c523925e..493f81dedc 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -1,594 +1,594 @@ -/** - * This software is provided under the terms of the Minecraft Forge Public - * License v1.0. - */ - -package net.minecraft.src.forge; - -import net.minecraft.src.BaseMod; -import net.minecraft.src.Block; -import net.minecraft.src.Chunk; -import net.minecraft.src.ChunkCoordIntPair; -import net.minecraft.src.Entity; -import net.minecraft.src.EntityItem; -import net.minecraft.src.EntityMinecart; -import net.minecraft.src.EntityPlayer; -import net.minecraft.src.IInventory; -import net.minecraft.src.ItemStack; -import net.minecraft.src.Item; -import net.minecraft.src.EnumStatus; -import net.minecraft.src.ModLoader; -import net.minecraft.src.NetworkManager; -import net.minecraft.src.Packet; -import net.minecraft.src.Packet1Login; -import net.minecraft.src.Packet250CustomPayload; -import net.minecraft.src.World; -import net.minecraft.src.forge.packets.PacketEntitySpawn; - -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.*; - -public class ForgeHooks -{ - // List Handling Hooks - // ------------------------------------------------------------ - public static void onTakenFromCrafting(EntityPlayer player, ItemStack stack, IInventory craftMatrix) - { - for (ICraftingHandler handler : craftingHandlers) - { - handler.onTakenFromCrafting(player, stack, craftMatrix); - } - } - static LinkedList craftingHandlers = new LinkedList(); - - public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig) - { - for (IDestroyToolHandler handler : destroyToolHandlers) - { - handler.onDestroyCurrentItem(player, orig); - } - } - static LinkedList destroyToolHandlers = new LinkedList(); - - public static boolean onUseBonemeal(World world, int blockID, int x, int y, int z) - { - for (IBonemealHandler handler : bonemealHandlers) - { - if (handler.onUseBonemeal(world, blockID, x, y, z)) - { - return true; - } - } - return false; - } - static LinkedList bonemealHandlers = new LinkedList(); - - public static boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, int x, int y, int z) - { - for (IHoeHandler handler : hoeHandlers) - { - if (handler.onUseHoe(hoe, player, world, x, y, z)) - { - return true; - } - } - return false; - } - static LinkedList hoeHandlers = new LinkedList(); - - public static EnumStatus sleepInBedAt(EntityPlayer player, int x, int y, int z) - { - for (ISleepHandler handler : sleepHandlers) - { - EnumStatus status = handler.sleepInBedAt(player, x, y, z); - if (status != null) - { - return status; - } - } - return null; - } - static LinkedList sleepHandlers = new LinkedList(); - - - public static void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z) - { - for (IMinecartHandler handler : minecartHandlers) - { - handler.onMinecartUpdate(minecart, x, y, z); - } - } - - public static void onMinecartEntityCollision(EntityMinecart minecart, Entity entity) - { - for (IMinecartHandler handler : minecartHandlers) - { - handler.onMinecartEntityCollision(minecart, entity); - } - } - - public static boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player) - { - boolean canceled = true; - for (IMinecartHandler handler : minecartHandlers) - { - boolean tmp = handler.onMinecartInteract(minecart, player, canceled); - canceled = canceled && tmp; - } - return canceled; - } - - static LinkedList minecartHandlers = new LinkedList(); - - public static void onConnect(NetworkManager network) - { - for (IConnectionHandler handler : connectionHandlers) - { - handler.onConnect(network); - } - } - - public static void onLogin(NetworkManager network, Packet1Login login) - { - for (IConnectionHandler handler : connectionHandlers) - { - handler.onLogin(network, login); - } - } - - public static void onDisconnect(NetworkManager network, String message, Object[] args) - { - for (IConnectionHandler handler : connectionHandlers) - { - handler.onDisconnect(network, message, args); - } - } - static LinkedList connectionHandlers = new LinkedList(); - - public static boolean onItemPickup(EntityPlayer player, EntityItem item) - { - boolean cont = true; - for (IPickupHandler handler : pickupHandlers) - { - cont = cont && handler.onItemPickup(player, item); - if (!cont || item.item.stackSize <= 0) - { - return false; - } - } - return cont; - } - static LinkedList pickupHandlers = new LinkedList(); - - public static void addActiveChunks(World world, Set chunkList) - { - for(IChunkLoadHandler loader : chunkLoadHandlers) - { - loader.addActiveChunks(world, chunkList); - } - } - - public static boolean canUnloadChunk(Chunk chunk) - { - for(IChunkLoadHandler loader : chunkLoadHandlers) - { - if(!loader.canUnloadChunk(chunk)) - { - return false; - } - } - return true; - } - - public static boolean canUpdateEntity(Entity entity) - { - for(IChunkLoadHandler loader : chunkLoadHandlers) - { - if(loader.canUpdateEntity(entity)) - { - return true; - } - } - return false; - } - static LinkedList chunkLoadHandlers = new LinkedList(); - - public static boolean onEntityInteract(EntityPlayer player, Entity entity, boolean isAttack) - { - for (IEntityInteractHandler handler : entityInteractHandlers) - { - if (!handler.onEntityInteract(player, entity, isAttack)) - { - return false; - } - } - return true; - } - static LinkedList entityInteractHandlers = new LinkedList(); - - public static String onServerChat(EntityPlayer player, String message) - { - for (IChatHandler handler : chatHandlers) - { - message = handler.onServerChat(player, message); - if (message == null) - { - return null; - } - } - return message; - } - - public static boolean onChatCommand(EntityPlayer player, boolean isOp, String command) - { - for (IChatHandler handler : chatHandlers) - { - if (handler.onChatCommand(player, isOp, command)) - { - return true; - } - } - return false; - } - - public static boolean onServerCommand(Object listener, String username, String command) - { - for (IChatHandler handler : chatHandlers) - { - if (handler.onServerCommand(listener, username, command)) - { - return true; - } - } - return false; - } - - public static String onServerCommandSay(Object listener, String username, String message) - { - for (IChatHandler handler : chatHandlers) - { - message = handler.onServerCommandSay(listener, username, message); - if (message == null) - { - return null; - } - } - return message; - } - - public static String onClientChatRecv(String message) - { - for (IChatHandler handler : chatHandlers) - { - message = handler.onClientChatRecv(message); - if (message == null) - { - return null; - } - } - return message; - } - static LinkedList chatHandlers = new LinkedList(); - - // Plant Management - // ------------------------------------------------------------ - static class ProbableItem - { - public ProbableItem(int item, int metadata, int quantity, int start, int end) - { - WeightStart = start; - WeightEnd = end; - ItemID = item; - Metadata = metadata; - Quantity = quantity; - } - int WeightStart, WeightEnd; - int ItemID, Metadata; - int Quantity; - } - - static ProbableItem getRandomItem(List list, int prop) - { - int n = Collections.binarySearch(list, prop, new Comparator() - { - public int compare(Object o1, Object o2) - { - ProbableItem pi = (ProbableItem)o1; - Integer i1 = (Integer)o2; - if (i1 < pi.WeightStart) - { - return 1; - } - if (i1 >= pi.WeightEnd) - { - return -1; - } - return 0; - } - }); - if (n < 0) - { - return null; - } - return list.get(n); - } - - static List plantGrassList; - static int plantGrassWeight; - - static List seedGrassList; - static int seedGrassWeight; - - public static void plantGrassPlant(World world, int x, int y, int z) - { - int index = world.rand.nextInt(plantGrassWeight); - ProbableItem item = getRandomItem(plantGrassList, index); - if (item == null) - { - return; - } - world.setBlockAndMetadataWithNotify(x, y, z, item.ItemID, item.Metadata); - } - - public static void addPlantGrass(int item, int metadata, int probability) - { - plantGrassList.add(new ProbableItem(item, metadata, 1, plantGrassWeight, plantGrassWeight + probability)); - plantGrassWeight += probability; - } - - public static ItemStack getGrassSeed(World world) - { - int index = world.rand.nextInt(seedGrassWeight); - ProbableItem item = getRandomItem(seedGrassList, index); - if (item == null) - { - return null; - } - return new ItemStack(item.ItemID, item.Quantity, item.Metadata); - } - - public static void addGrassSeed(int item, int metadata, int quantity, int probability) - { - seedGrassList.add(new ProbableItem(item, metadata, quantity, seedGrassWeight, seedGrassWeight + probability)); - seedGrassWeight += probability; - } - - // Tool Path - // ------------------------------------------------------------ - public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata) - { - if (block.blockMaterial.isHarvestable()) - { - return true; - } - ItemStack stack = player.inventory.getCurrentItem(); - if (stack == null) - { - return false; - } - - List info = (List)toolClasses.get(stack.itemID); - if (info == null) - { - return stack.canHarvestBlock(block); - } - Object[] tmp = info.toArray(); - String toolClass = (String)tmp[0]; - int harvestLevel = (Integer)tmp[1]; - - Integer blockHarvestLevel = (Integer)toolHarvestLevels.get(Arrays.asList(block.blockID, metadata, toolClass)); - if (blockHarvestLevel == null) - { - return stack.canHarvestBlock(block); - } - if (blockHarvestLevel > harvestLevel) - { - return false; - } - return true; - } - - public static float blockStrength(Block block, EntityPlayer player, int metadata) - { - float hardness = block.getHardness(metadata); - if (hardness < 0.0F) - { - return 0.0F; - } - - if (!canHarvestBlock(block, player, metadata)) - { - return 1.0F / hardness / 100F; - } - else - { - return player.getCurrentPlayerStrVsBlock(block, metadata) / hardness / 30F; - } - } - - public static boolean isToolEffective(ItemStack stack, Block block, int metadata) - { - List toolClass = (List)toolClasses.get(stack.itemID); - if (toolClass == null) - { - return false; - } - return toolEffectiveness.contains(Arrays.asList(block.blockID, metadata, (String)toolClass.get(0))); - } - - static void initTools() - { - if (toolInit) - { - return; - } - toolInit = true; - - MinecraftForge.setToolClass(Item.pickaxeWood, "pickaxe", 0); - MinecraftForge.setToolClass(Item.pickaxeStone, "pickaxe", 1); - MinecraftForge.setToolClass(Item.pickaxeSteel, "pickaxe", 2); - MinecraftForge.setToolClass(Item.pickaxeGold, "pickaxe", 0); - MinecraftForge.setToolClass(Item.pickaxeDiamond, "pickaxe", 3); - - MinecraftForge.setToolClass(Item.axeWood, "axe", 0); - MinecraftForge.setToolClass(Item.axeStone, "axe", 1); - MinecraftForge.setToolClass(Item.axeSteel, "axe", 2); - MinecraftForge.setToolClass(Item.axeGold, "axe", 0); - MinecraftForge.setToolClass(Item.axeDiamond, "axe", 3); - - MinecraftForge.setToolClass(Item.shovelWood, "shovel", 0); - MinecraftForge.setToolClass(Item.shovelStone, "shovel", 1); - MinecraftForge.setToolClass(Item.shovelSteel, "shovel", 2); - MinecraftForge.setToolClass(Item.shovelGold, "shovel", 0); - MinecraftForge.setToolClass(Item.shovelDiamond, "shovel", 3); - - MinecraftForge.setBlockHarvestLevel(Block.obsidian, "pickaxe", 3); - MinecraftForge.setBlockHarvestLevel(Block.oreDiamond, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.blockDiamond, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreGold, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.blockGold, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreIron, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.blockSteel, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.oreLapis, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.blockLapis, "pickaxe", 1); - MinecraftForge.setBlockHarvestLevel(Block.oreRedstone, "pickaxe", 2); - MinecraftForge.setBlockHarvestLevel(Block.oreRedstoneGlowing, "pickaxe", 2); - MinecraftForge.removeBlockEffectiveness(Block.oreRedstone, "pickaxe"); - MinecraftForge.removeBlockEffectiveness(Block.obsidian, "pickaxe"); - MinecraftForge.removeBlockEffectiveness(Block.oreRedstoneGlowing, "pickaxe"); - - Block[] pickeff = - { - Block.cobblestone, Block.stairDouble, - Block.stairSingle, Block.stone, - Block.sandStone, Block.cobblestoneMossy, - Block.oreCoal, Block.ice, - Block.netherrack, Block.oreLapis, - Block.blockLapis - }; - for (Block block : pickeff) - { - MinecraftForge.setBlockHarvestLevel(block, "pickaxe", 0); - } - - Block[] spadeEff = - { - Block.grass, Block.dirt, - Block.sand, Block.gravel, - Block.snow, Block.blockSnow, - Block.blockClay, Block.tilledField, - Block.slowSand, Block.mycelium - }; - for (Block block : spadeEff) - { - MinecraftForge.setBlockHarvestLevel(block, "shovel", 0); - } - - Block[] axeEff = - { - Block.planks, Block.bookShelf, - Block.wood, Block.chest, - Block.stairDouble, Block.stairSingle, - Block.pumpkin, Block.pumpkinLantern - }; - for (Block block : axeEff) - { - MinecraftForge.setBlockHarvestLevel(block, "axe", 0); - } - - } - - public static HashMap entityTrackerMap = new HashMap(); - - /** - * Builds the 'Spawn' packet using the Custom Payload packet on the 'Forge' channel. - * Supports entities that have custom spawn data, as well as the generic 'Owner' construct. - * - * @param entity The entity instance to spawn - * @return The spawn packet, or null if we arn't spawning it. - */ - public static Packet getEntitySpawnPacket(Entity entity) - { - EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, false); - if (info == null) - { - return null; - } - - PacketEntitySpawn pkt = new PacketEntitySpawn(entity, info.Mod, info.ID); - return pkt.getPacket(); - } - - public static Hashtable networkMods = new Hashtable(); - public static Hashtable guiHandlers = new Hashtable(); - - public static boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime) - { - for (IArrowLooseHandler handler : arrowLooseHandlers) - { - if (handler.onArrowLoose(itemstack, world, player, heldTime)) - { - return true; - } - } - return false; - } - - public static ArrayList arrowLooseHandlers = new ArrayList(); - - public static ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player) - { - for (IArrowNockHandler handler : arrowNockHandlers) - { - ItemStack ret = handler.onArrowNock(itemstack, world, player); - if (ret != null) - { - return ret; - } - } - return null; - } - public static ArrayList arrowNockHandlers = new ArrayList(); - - public static final int majorVersion=0; - public static final int minorVersion=0; - public static final int revisionVersion=0; - public static final int buildVersion=0; - static - { - plantGrassList = new ArrayList(); - plantGrassList.add(new ProbableItem(Block.plantYellow.blockID, 0, 1, 0, 20)); - plantGrassList.add(new ProbableItem(Block.plantRed.blockID, 0, 1, 20, 30)); - plantGrassWeight = 30; - - seedGrassList = new ArrayList(); - seedGrassList.add(new ProbableItem(Item.seeds.shiftedIndex, 0, 1, 0, 10)); - seedGrassWeight = 10; - - System.out.printf("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion); - ModLoader.getLogger().info(String.format("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion)); - } - - static boolean toolInit = false; - static HashMap toolClasses = new HashMap(); - static HashMap toolHarvestLevels = new HashMap(); - static HashSet toolEffectiveness = new HashSet(); - - private static IPacketHandler forgePacketHandler = null; - public static void setPacketHandler(IPacketHandler handler) - { - if (forgePacketHandler != null) - { - throw new RuntimeException("Attempted to set Forge's Internal packet handler after it was already set"); - } - forgePacketHandler = handler; - } - public static IPacketHandler getPacketHandler() - { - return forgePacketHandler; - } -} - +/** + * This software is provided under the terms of the Minecraft Forge Public + * License v1.0. + */ + +package net.minecraft.src.forge; + +import net.minecraft.src.BaseMod; +import net.minecraft.src.Block; +import net.minecraft.src.Chunk; +import net.minecraft.src.ChunkCoordIntPair; +import net.minecraft.src.Entity; +import net.minecraft.src.EntityItem; +import net.minecraft.src.EntityMinecart; +import net.minecraft.src.EntityPlayer; +import net.minecraft.src.IInventory; +import net.minecraft.src.ItemStack; +import net.minecraft.src.Item; +import net.minecraft.src.EnumStatus; +import net.minecraft.src.ModLoader; +import net.minecraft.src.NetworkManager; +import net.minecraft.src.Packet; +import net.minecraft.src.Packet1Login; +import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.World; +import net.minecraft.src.forge.packets.PacketEntitySpawn; + +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.*; + +public class ForgeHooks +{ + // List Handling Hooks + // ------------------------------------------------------------ + public static void onTakenFromCrafting(EntityPlayer player, ItemStack stack, IInventory craftMatrix) + { + for (ICraftingHandler handler : craftingHandlers) + { + handler.onTakenFromCrafting(player, stack, craftMatrix); + } + } + static LinkedList craftingHandlers = new LinkedList(); + + public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig) + { + for (IDestroyToolHandler handler : destroyToolHandlers) + { + handler.onDestroyCurrentItem(player, orig); + } + } + static LinkedList destroyToolHandlers = new LinkedList(); + + public static boolean onUseBonemeal(World world, int blockID, int x, int y, int z) + { + for (IBonemealHandler handler : bonemealHandlers) + { + if (handler.onUseBonemeal(world, blockID, x, y, z)) + { + return true; + } + } + return false; + } + static LinkedList bonemealHandlers = new LinkedList(); + + public static boolean onUseHoe(ItemStack hoe, EntityPlayer player, World world, int x, int y, int z) + { + for (IHoeHandler handler : hoeHandlers) + { + if (handler.onUseHoe(hoe, player, world, x, y, z)) + { + return true; + } + } + return false; + } + static LinkedList hoeHandlers = new LinkedList(); + + public static EnumStatus sleepInBedAt(EntityPlayer player, int x, int y, int z) + { + for (ISleepHandler handler : sleepHandlers) + { + EnumStatus status = handler.sleepInBedAt(player, x, y, z); + if (status != null) + { + return status; + } + } + return null; + } + static LinkedList sleepHandlers = new LinkedList(); + + + public static void onMinecartUpdate(EntityMinecart minecart, int x, int y, int z) + { + for (IMinecartHandler handler : minecartHandlers) + { + handler.onMinecartUpdate(minecart, x, y, z); + } + } + + public static void onMinecartEntityCollision(EntityMinecart minecart, Entity entity) + { + for (IMinecartHandler handler : minecartHandlers) + { + handler.onMinecartEntityCollision(minecart, entity); + } + } + + public static boolean onMinecartInteract(EntityMinecart minecart, EntityPlayer player) + { + boolean canceled = true; + for (IMinecartHandler handler : minecartHandlers) + { + boolean tmp = handler.onMinecartInteract(minecart, player, canceled); + canceled = canceled && tmp; + } + return canceled; + } + + static LinkedList minecartHandlers = new LinkedList(); + + public static void onConnect(NetworkManager network) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.onConnect(network); + } + } + + public static void onLogin(NetworkManager network, Packet1Login login) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.onLogin(network, login); + } + } + + public static void onDisconnect(NetworkManager network, String message, Object[] args) + { + for (IConnectionHandler handler : connectionHandlers) + { + handler.onDisconnect(network, message, args); + } + } + static LinkedList connectionHandlers = new LinkedList(); + + public static boolean onItemPickup(EntityPlayer player, EntityItem item) + { + boolean cont = true; + for (IPickupHandler handler : pickupHandlers) + { + cont = cont && handler.onItemPickup(player, item); + if (!cont || item.item.stackSize <= 0) + { + return false; + } + } + return cont; + } + static LinkedList pickupHandlers = new LinkedList(); + + public static void addActiveChunks(World world, Set chunkList) + { + for(IChunkLoadHandler loader : chunkLoadHandlers) + { + loader.addActiveChunks(world, chunkList); + } + } + + public static boolean canUnloadChunk(Chunk chunk) + { + for(IChunkLoadHandler loader : chunkLoadHandlers) + { + if(!loader.canUnloadChunk(chunk)) + { + return false; + } + } + return true; + } + + public static boolean canUpdateEntity(Entity entity) + { + for(IChunkLoadHandler loader : chunkLoadHandlers) + { + if(loader.canUpdateEntity(entity)) + { + return true; + } + } + return false; + } + static LinkedList chunkLoadHandlers = new LinkedList(); + + public static boolean onEntityInteract(EntityPlayer player, Entity entity, boolean isAttack) + { + for (IEntityInteractHandler handler : entityInteractHandlers) + { + if (!handler.onEntityInteract(player, entity, isAttack)) + { + return false; + } + } + return true; + } + static LinkedList entityInteractHandlers = new LinkedList(); + + public static String onServerChat(EntityPlayer player, String message) + { + for (IChatHandler handler : chatHandlers) + { + message = handler.onServerChat(player, message); + if (message == null) + { + return null; + } + } + return message; + } + + public static boolean onChatCommand(EntityPlayer player, boolean isOp, String command) + { + for (IChatHandler handler : chatHandlers) + { + if (handler.onChatCommand(player, isOp, command)) + { + return true; + } + } + return false; + } + + public static boolean onServerCommand(Object listener, String username, String command) + { + for (IChatHandler handler : chatHandlers) + { + if (handler.onServerCommand(listener, username, command)) + { + return true; + } + } + return false; + } + + public static String onServerCommandSay(Object listener, String username, String message) + { + for (IChatHandler handler : chatHandlers) + { + message = handler.onServerCommandSay(listener, username, message); + if (message == null) + { + return null; + } + } + return message; + } + + public static String onClientChatRecv(String message) + { + for (IChatHandler handler : chatHandlers) + { + message = handler.onClientChatRecv(message); + if (message == null) + { + return null; + } + } + return message; + } + static LinkedList chatHandlers = new LinkedList(); + + // Plant Management + // ------------------------------------------------------------ + static class ProbableItem + { + public ProbableItem(int item, int metadata, int quantity, int start, int end) + { + WeightStart = start; + WeightEnd = end; + ItemID = item; + Metadata = metadata; + Quantity = quantity; + } + int WeightStart, WeightEnd; + int ItemID, Metadata; + int Quantity; + } + + static ProbableItem getRandomItem(List list, int prop) + { + int n = Collections.binarySearch(list, prop, new Comparator() + { + public int compare(Object o1, Object o2) + { + ProbableItem pi = (ProbableItem)o1; + Integer i1 = (Integer)o2; + if (i1 < pi.WeightStart) + { + return 1; + } + if (i1 >= pi.WeightEnd) + { + return -1; + } + return 0; + } + }); + if (n < 0) + { + return null; + } + return list.get(n); + } + + static List plantGrassList; + static int plantGrassWeight; + + static List seedGrassList; + static int seedGrassWeight; + + public static void plantGrassPlant(World world, int x, int y, int z) + { + int index = world.rand.nextInt(plantGrassWeight); + ProbableItem item = getRandomItem(plantGrassList, index); + if (item == null) + { + return; + } + world.setBlockAndMetadataWithNotify(x, y, z, item.ItemID, item.Metadata); + } + + public static void addPlantGrass(int item, int metadata, int probability) + { + plantGrassList.add(new ProbableItem(item, metadata, 1, plantGrassWeight, plantGrassWeight + probability)); + plantGrassWeight += probability; + } + + public static ItemStack getGrassSeed(World world) + { + int index = world.rand.nextInt(seedGrassWeight); + ProbableItem item = getRandomItem(seedGrassList, index); + if (item == null) + { + return null; + } + return new ItemStack(item.ItemID, item.Quantity, item.Metadata); + } + + public static void addGrassSeed(int item, int metadata, int quantity, int probability) + { + seedGrassList.add(new ProbableItem(item, metadata, quantity, seedGrassWeight, seedGrassWeight + probability)); + seedGrassWeight += probability; + } + + // Tool Path + // ------------------------------------------------------------ + public static boolean canHarvestBlock(Block block, EntityPlayer player, int metadata) + { + if (block.blockMaterial.isHarvestable()) + { + return true; + } + ItemStack stack = player.inventory.getCurrentItem(); + if (stack == null) + { + return false; + } + + List info = (List)toolClasses.get(stack.itemID); + if (info == null) + { + return stack.canHarvestBlock(block); + } + Object[] tmp = info.toArray(); + String toolClass = (String)tmp[0]; + int harvestLevel = (Integer)tmp[1]; + + Integer blockHarvestLevel = (Integer)toolHarvestLevels.get(Arrays.asList(block.blockID, metadata, toolClass)); + if (blockHarvestLevel == null) + { + return stack.canHarvestBlock(block); + } + if (blockHarvestLevel > harvestLevel) + { + return false; + } + return true; + } + + public static float blockStrength(Block block, EntityPlayer player, int metadata) + { + float hardness = block.getHardness(metadata); + if (hardness < 0.0F) + { + return 0.0F; + } + + if (!canHarvestBlock(block, player, metadata)) + { + return 1.0F / hardness / 100F; + } + else + { + return player.getCurrentPlayerStrVsBlock(block, metadata) / hardness / 30F; + } + } + + public static boolean isToolEffective(ItemStack stack, Block block, int metadata) + { + List toolClass = (List)toolClasses.get(stack.itemID); + if (toolClass == null) + { + return false; + } + return toolEffectiveness.contains(Arrays.asList(block.blockID, metadata, (String)toolClass.get(0))); + } + + static void initTools() + { + if (toolInit) + { + return; + } + toolInit = true; + + MinecraftForge.setToolClass(Item.pickaxeWood, "pickaxe", 0); + MinecraftForge.setToolClass(Item.pickaxeStone, "pickaxe", 1); + MinecraftForge.setToolClass(Item.pickaxeSteel, "pickaxe", 2); + MinecraftForge.setToolClass(Item.pickaxeGold, "pickaxe", 0); + MinecraftForge.setToolClass(Item.pickaxeDiamond, "pickaxe", 3); + + MinecraftForge.setToolClass(Item.axeWood, "axe", 0); + MinecraftForge.setToolClass(Item.axeStone, "axe", 1); + MinecraftForge.setToolClass(Item.axeSteel, "axe", 2); + MinecraftForge.setToolClass(Item.axeGold, "axe", 0); + MinecraftForge.setToolClass(Item.axeDiamond, "axe", 3); + + MinecraftForge.setToolClass(Item.shovelWood, "shovel", 0); + MinecraftForge.setToolClass(Item.shovelStone, "shovel", 1); + MinecraftForge.setToolClass(Item.shovelSteel, "shovel", 2); + MinecraftForge.setToolClass(Item.shovelGold, "shovel", 0); + MinecraftForge.setToolClass(Item.shovelDiamond, "shovel", 3); + + MinecraftForge.setBlockHarvestLevel(Block.obsidian, "pickaxe", 3); + MinecraftForge.setBlockHarvestLevel(Block.oreDiamond, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.blockDiamond, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreGold, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.blockGold, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreIron, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.blockSteel, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.oreLapis, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.blockLapis, "pickaxe", 1); + MinecraftForge.setBlockHarvestLevel(Block.oreRedstone, "pickaxe", 2); + MinecraftForge.setBlockHarvestLevel(Block.oreRedstoneGlowing, "pickaxe", 2); + MinecraftForge.removeBlockEffectiveness(Block.oreRedstone, "pickaxe"); + MinecraftForge.removeBlockEffectiveness(Block.obsidian, "pickaxe"); + MinecraftForge.removeBlockEffectiveness(Block.oreRedstoneGlowing, "pickaxe"); + + Block[] pickeff = + { + Block.cobblestone, Block.stairDouble, + Block.stairSingle, Block.stone, + Block.sandStone, Block.cobblestoneMossy, + Block.oreCoal, Block.ice, + Block.netherrack, Block.oreLapis, + Block.blockLapis + }; + for (Block block : pickeff) + { + MinecraftForge.setBlockHarvestLevel(block, "pickaxe", 0); + } + + Block[] spadeEff = + { + Block.grass, Block.dirt, + Block.sand, Block.gravel, + Block.snow, Block.blockSnow, + Block.blockClay, Block.tilledField, + Block.slowSand, Block.mycelium + }; + for (Block block : spadeEff) + { + MinecraftForge.setBlockHarvestLevel(block, "shovel", 0); + } + + Block[] axeEff = + { + Block.planks, Block.bookShelf, + Block.wood, Block.chest, + Block.stairDouble, Block.stairSingle, + Block.pumpkin, Block.pumpkinLantern + }; + for (Block block : axeEff) + { + MinecraftForge.setBlockHarvestLevel(block, "axe", 0); + } + + } + + public static HashMap entityTrackerMap = new HashMap(); + + /** + * Builds the 'Spawn' packet using the Custom Payload packet on the 'Forge' channel. + * Supports entities that have custom spawn data, as well as the generic 'Owner' construct. + * + * @param entity The entity instance to spawn + * @return The spawn packet, or null if we arn't spawning it. + */ + public static Packet getEntitySpawnPacket(Entity entity) + { + EntityTrackerInfo info = MinecraftForge.getEntityTrackerInfo(entity, false); + if (info == null) + { + return null; + } + + PacketEntitySpawn pkt = new PacketEntitySpawn(entity, info.Mod, info.ID); + return pkt.getPacket(); + } + + public static Hashtable networkMods = new Hashtable(); + public static Hashtable guiHandlers = new Hashtable(); + + public static boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime) + { + for (IArrowLooseHandler handler : arrowLooseHandlers) + { + if (handler.onArrowLoose(itemstack, world, player, heldTime)) + { + return true; + } + } + return false; + } + + public static ArrayList arrowLooseHandlers = new ArrayList(); + + public static ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player) + { + for (IArrowNockHandler handler : arrowNockHandlers) + { + ItemStack ret = handler.onArrowNock(itemstack, world, player); + if (ret != null) + { + return ret; + } + } + return null; + } + public static ArrayList arrowNockHandlers = new ArrayList(); + + public static final int majorVersion = 3; + public static final int minorVersion = 0; + public static final int revisionVersion = 0; + public static final int buildVersion = 0; + static + { + plantGrassList = new ArrayList(); + plantGrassList.add(new ProbableItem(Block.plantYellow.blockID, 0, 1, 0, 20)); + plantGrassList.add(new ProbableItem(Block.plantRed.blockID, 0, 1, 20, 30)); + plantGrassWeight = 30; + + seedGrassList = new ArrayList(); + seedGrassList.add(new ProbableItem(Item.seeds.shiftedIndex, 0, 1, 0, 10)); + seedGrassWeight = 10; + + System.out.printf("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion); + ModLoader.getLogger().info(String.format("MinecraftForge v%d.%d.%d.%d Initialized\n", majorVersion, minorVersion, revisionVersion, buildVersion)); + } + + static boolean toolInit = false; + static HashMap toolClasses = new HashMap(); + static HashMap toolHarvestLevels = new HashMap(); + static HashSet toolEffectiveness = new HashSet(); + + private static IPacketHandler forgePacketHandler = null; + public static void setPacketHandler(IPacketHandler handler) + { + if (forgePacketHandler != null) + { + throw new RuntimeException("Attempted to set Forge's Internal packet handler after it was already set"); + } + forgePacketHandler = handler; + } + public static IPacketHandler getPacketHandler() + { + return forgePacketHandler; + } +} + diff --git a/forge/inject_version.bat b/forge/inject_version.bat deleted file mode 100644 index a002849177..0000000000 --- a/forge/inject_version.bat +++ /dev/null @@ -1,20 +0,0 @@ -@echo off -setlocal enableextensions enabledelayedexpansion -FOR /F "tokens=1-4" %%A IN (version.txt) DO ( - set major=%%A - set minor=%%B - set revision=%%C - set build=%%D -) -set file=%* - -echo Injecting Revision !major!.!minor!.!revision!.!build! %file% - -set PATH=.\bin;%PATH% -sed s/majorVersion=0/majorVersion=!major!/ !file!.tmp - -move /Y !file:/=\!.tmp !file:/=\! >nul diff --git a/forge/inject_version.sh b/forge/inject_version.sh deleted file mode 100755 index 4aa41ae455..0000000000 --- a/forge/inject_version.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -target=$1 -read major minor rev build $target.tmp - -mv $target.tmp $target \ No newline at end of file diff --git a/forge/lfcr.py b/forge/lfcr.py deleted file mode 100644 index d6ad3ee6c6..0000000000 --- a/forge/lfcr.py +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/bin/env python - -import sys, re, os -data = open(sys.argv[1], "rb").read() -newdata = re.sub("\r?\n", "\r\n", data) -f = open(sys.argv[2], "wb") -f.write(newdata) -f.close() \ No newline at end of file diff --git a/forge/package.sh b/forge/package.sh deleted file mode 100755 index 599ba565f5..0000000000 --- a/forge/package.sh +++ /dev/null @@ -1,69 +0,0 @@ -read major minor revision build 1: + try: + build_num = int(sys.argv[1]) + except: + pass + ret = 0 + ret = build(build_num) + if ret != 0: + sys.exit(ret) + + print '=================================== Release Start =================================' + error_level = 0 + try: + os.chdir(mcp_dir) + reobfuscate(None, False, True, True) + reset_logger() + os.chdir(forge_dir) + except SystemExit, e: + print 'Reobfusicate Exception: %d ' % e.code + error_level = e.code + + out_folder = os.path.join(forge_dir, 'forge-%s' % version_str) + if os.path.isdir(out_folder): + shutil.rmtree(out_folder) + + os.makedirs(out_folder) + + extract_fml_obfed() + version = load_version(build_num) + version_str = '%d.%d.%d.%d' % (version['major'], version['minor'], version['revision'], version['build']) + + zip_start('minecraftforge-client-%s.zip' % version_str) + zip_folder(client_dir, '', zip) + zip_add('minecraftforge_credits.txt') + zip_add('license.txt') + zip_end() + + zip_start('minecraftforge-server-%s.zip' % version_str) + zip_folder(server_dir, '', zip) + zip_add('minecraftforge_credits.txt') + zip_add('license.txt') + zip_end() + + zip_start('minecraftforge-src-%s.zip' % version_str, 'forge') + zip_add('forge_client/src', 'src/minecraft') + zip_add('forge_server/src', 'src/minecraft_server') + zip_add('forge_common', 'src/minecraft') + zip_add('forge_common', 'src/minecraft_server') + zip_add('patches', 'patches') + zip_add('fml', 'fml') + zip_add('conf', 'conf') + zip_add('minecraftforge_credits.txt') + zip_add('install/install.cmd') + zip_add('install/install.sh') + zip_add('install/README.txt') + zip_add('install/install.py') + zip_add('forge.py') + zip_add('minecraftforge_credits.txt') + zip_add('license.txt') + zip_end() + + print '=================================== Release Finished %d =================================' % error_level + sys.exit(error_level) + + +def zip_add(file, key=None): + if key == None: + key = os.path.basename(file) + else: + key = key.replace('/', os.sep) + if not zip_base is None: + key = os.path.join(zip_base, key) + file = os.path.join(forge_dir, file.replace('/', os.sep)) + if os.path.isdir(file): + zip_folder(file, key, zip) + else: + if os.path.isfile(file): + print key + zip.write(file, key) + +def zip_start(name, base=None): + global zip, zip_name, zip_base + zip_name = name + + print '=================================== %s Start =================================' % zip_name + zip_file = os.path.join(forge_dir, 'forge-%s' % version_str, name) + zip = zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) + zip_base = base + +def zip_end(): + global zip, zip_name, zip_base + zip.close() + print '=================================== %s Finished =================================' % zip_name + zip_name = None + zip_base = None + +def extract_fml_obfed(): + fml_file = os.path.join(forge_dir, 'fml', 'difflist.txt') + if not os.path.isfile(fml_file): + print 'Could not find Forge ModLoader\'s DiffList, looking for it at: %s' % fml_file + sys.exit(1) + + with open(fml_file, 'r') as fh: + lines = fh.readlines() + + client = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'client_reobf.jar')) + server = zipfile.ZipFile(os.path.join(mcp_dir, 'temp', 'server_reobf.jar')) + + print 'Extracting Reobfed Forge ModLoader classes' + for line in lines: + line = line.replace('\n', '').replace('\r', '').replace('/', os.sep) + print line + if not os.path.isfile(os.path.join(reobf_dir, line)): + side = line.split(os.sep)[0] + if side == 'minecraft': + client.extract(line[10:].replace(os.sep, '/'), client_dir) + else: + server.extract(line[17:].replace(os.sep, '/'), server_dir) + + client.close() + server.close() + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/forge/setup.bat b/forge/setup.bat index a6fa1576d3..1b96a5d70d 100755 --- a/forge/setup.bat +++ b/forge/setup.bat @@ -1,51 +1,5 @@ @echo off -echo =================================== Setup Start ================================= -pushd .. >nul - - if "%1"=="-skipdecompile" ( - @echo | cmd /C updatenames.bat -f - ) ELSE ( - if not exist "runtime\bin\fernflower.jar" ( - pushd forge - ..\runtime\bin\python\python_mcp download_fernflower.py - popd - ) - if not exist "runtime\bin\fernflower.jar" ( - echo Failed to download fernflower, install it manually and re-run setup. - exit 1 - ) - rmdir /S /Q src - echo | cmd /C decompile.bat -r - ) - - echo | cmd /C updatemd5.bat -f - - rmdir /S /Q src_base - rmdir /S /Q src_work - mkdir src_base - mkdir src_work - - xcopy /Y /E /Q src\* src_base - xcopy /Y /E /Q src\* src_work - - pushd src_work >nul - @setlocal enabledelayedexpansion - @echo off - - set PATH=..\forge\bin;%PATH% - echo Applying patches - for /f %%i in ('find ../forge/patches -type f') do ( - set file=%%i - if /I "!file:~-6!" EQU ".patch" ( - ..\runtime\bin\python\python_mcp ..\forge\lfcr.py %%i ..\forge\temp.patch - ..\runtime\bin\applydiff.exe -uf -p2 -i ..\forge\temp.patch - del ..\forge\temp.patch >nul 1>nul - ) - ) - popd >nul -popd >nul -echo =================================== Setup Finished ================================= - +..\runtime\bin\python\python_mcp setup.py %* if NOT "%1"=="-skipdecompile" ( pause ) \ No newline at end of file diff --git a/forge/setup.py b/forge/setup.py new file mode 100644 index 0000000000..24016693a5 --- /dev/null +++ b/forge/setup.py @@ -0,0 +1,93 @@ +import os, os.path, sys +import urllib, zipfile +import shutil, glob, fnmatch +import subprocess, logging + +forge_dir = os.path.dirname(os.path.abspath(__file__)) +mcp_dir = os.path.abspath('..') +src_dir = os.path.join(mcp_dir, 'src') + +sys.path.append(mcp_dir) +from runtime.decompile import decompile +from runtime.updatenames import updatenames +from runtime.updatemd5 import updatemd5 + +from forge import apply_patches, copytree, reset_logger, download_ff + + +def main(): + print '=================================== Setup Start =================================' + + skipDecompile = len(sys.argv) > 1 and sys.argv[1] == '-skipdecompile' + if not skipDecompile: + if not download_ff(mcp_dir): + sys.exit(1) + + if os.path.isdir(src_dir): + shutil.rmtree(src_dir) + try: + os.chdir(mcp_dir) + # Conf JAD CSV -r -d -a -n -p -o -l -g + decompile(None, False, False, True, True, False, True, False, False, False, False) + reset_logger() + os.chdir(forge_dir) + except SystemExit, e: + print 'Decompile Exception: %d ' % e.code + raise e + + if not os.path.isdir(src_dir): + print 'Something went wrong, src folder not found at: %s' % src_dir + sys.exit(1) + + setup_fml() + + os.chdir(mcp_dir) + updatenames(None, True) + reset_logger() + updatemd5(None, True) + reset_logger() + os.chdir(forge_dir) + + base_dir = os.path.join(mcp_dir, 'src_base') + work_dir = os.path.join(mcp_dir, 'src_work') + + if os.path.isdir(base_dir): + shutil.rmtree(base_dir) + if os.path.isdir(work_dir): + shutil.rmtree(work_dir) + + print 'Setting up source directories' + shutil.copytree(src_dir, base_dir) + shutil.copytree(src_dir, work_dir) + + print 'Applying forge patches' + apply_patches(os.path.join(forge_dir, 'patches'), work_dir) + + print '=================================== Setup Finished =================================' + +def setup_fml(): + print 'Setting up Forge ModLoader' + fml = glob.glob(os.path.join(forge_dir, 'fml-src-*.zip')) + if not len(fml) == 1: + if len(fml) == 0: + print 'Missing FML source zip, should be named fml-src-*.zip inside your forge folder, obtain it from the repo' + else: + print 'To many FML source zips found, we should only have one. Check the Forge Git for the latest FML version supported' + sys.exit(1) + + fml_dir = os.path.join(forge_dir, 'fml') + if os.path.isdir(fml_dir): + shutil.rmtree(fml_dir) + + print 'Extracting Forge ModLoader: %s' % os.path.basename(fml[0]) + + zf = zipfile.ZipFile(fml[0]) + zf.extractall(forge_dir) + zf.close() + + print 'Applying Forge ModLoader patches' + apply_patches(os.path.join(fml_dir, 'patches'), src_dir) + copytree(os.path.join(fml_dir, 'src'), src_dir) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/forge/version.txt b/forge/version.txt deleted file mode 100644 index f3be5a5c58..0000000000 --- a/forge/version.txt +++ /dev/null @@ -1 +0,0 @@ -2 0 0 0