diff --git a/forge/forge.py b/forge/forge.py index 590d76bdb..719df8d95 100644 --- a/forge/forge.py +++ b/forge/forge.py @@ -161,9 +161,9 @@ def inject_version(src_file, build=0): pass return match.group(0) - buf = version_reg.sub(mapname, buf) + buf = version_reg.sub(mapname, buf).replace('\r\n', '\n') - with open(tmp_file, 'w') as fh: + with open(tmp_file, 'wb') as fh: fh.write(buf) shutil.move(tmp_file, src_file) diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index 493f81ded..fd520bb08 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 = 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; - } -} - +/** + * 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 = 5; + 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/install/install.cmd b/forge/install/install.cmd index 55ac1a0fa..d53676106 100755 --- a/forge/install/install.cmd +++ b/forge/install/install.cmd @@ -1,57 +1,3 @@ -echo off - -echo MinecraftForge Windows Setup Program -echo: - -@set PATH=%PATH%;%SystemDir%\system32;%SystemRoot%\System32 - -if not exist "..\runtime\bin\fernflower.jar" ( - ..\runtime\bin\python\python_mcp download_fernflower.py -) -if not exist "..\runtime\bin\fernflower.jar" ( - echo Failed to download fernflower, install it manually and re-run setup. - exit 1 -) - -pushd .. >nul - -xcopy /Y /E /I forge\conf\* conf - -if exist ".\src" ( - runtime\bin\python\python_mcp runtime\cleanup.py -) -if exist ".\src" ( - echo Please make sure to backup your modified files, and say yes when it asks you to do cleanup. - exit 1 -) -runtime\bin\python\python_mcp runtime\decompile.py - -pushd src >nul - - if exist ..\jars\bin\minecraft.jar ( - for /f "delims=" %%a in ('dir /a -d /b /S ..\forge\patches\minecraft') do ( - pushd "%%a" 2>nul - if errorlevel 1 ( - ..\runtime\bin\python\python_mcp ..\forge\lfcr.py "%%a" "%%a" - ..\runtime\bin\applydiff.exe -uf -p2 -i "%%a" - ) else popd - ) - xcopy /Y /E ..\forge\src\minecraft\* minecraft - ) - - if exist ..\jars\minecraft_server.jar ( - for /f "delims=" %%a in ('dir /a -d /b /S ..\forge\patches\minecraft_server') do ( - pushd "%%a" 2>nul - if errorlevel 1 ( - ..\runtime\bin\python\python_mcp ..\forge\lfcr.py "%%a" "%%a" - ..\runtime\bin\applydiff.exe -uf -p2 -i "%%a" - ) else popd - ) - xcopy /Y /E ..\forge\src\minecraft_server\* minecraft_server - ) -popd >nul - -runtime\bin\python\python_mcp runtime\updatemcp.py -f -runtime\bin\python\python_mcp runtime\updatenames.py -f -runtime\bin\python\python_mcp runtime\updatemd5.py -f +@echo off +..\runtime\bin\python\python_mcp install.py pause \ No newline at end of file diff --git a/forge/install/install.py b/forge/install/install.py new file mode 100644 index 000000000..2d6dff5dc --- /dev/null +++ b/forge/install/install.py @@ -0,0 +1,98 @@ +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 runtime.cleanup import cleanup +from runtime.updatemcp import updatemcp + +from forge import apply_patches, copytree, reset_logger, download_ff + +def main(): + print '=================================== Minecraft Forge Setup Start =================================' + + if os.path.isdir(os.path.join(mcp_dir, 'conf')): + shutil.rmtree(os.path.join(mcp_dir, 'conf')) + copytree(os.path.join(forge_dir, 'conf'), os.path.join(mcp_dir, 'conf')) + + if os.path.isdir(src_dir): + os.chdir(mcp_dir) + cleanup(None, False) + reset_logger() + os.chdir(forge_dir) + + if os.path.isdir(src_dir): + print 'Please make sure to backup your modified files, and say yes when it asks you to do cleanup.' + sys.exit(1) + + if not download_ff(mcp_dir): + sys.exit(1) + + 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) + + has_client = os.path.isdir(os.path.join(mcp_dir, 'src', 'minecraft')) + has_server = os.path.isdir(os.path.join(mcp_dir, 'src', 'minecraft_server')) + + fml_dir = os.path.join(forge_dir, 'fml') + print 'Applying Forge ModLoader patches' + if has_client: + if os.path.isdir(os.path.join(fml_dir, 'patches', 'minecraft')): + apply_patches(os.path.join(fml_dir, 'patches', 'minecraft'), src_dir) + if os.path.isdir(os.path.join(fml_dir, 'src', 'minecraft')): + copytree(os.path.join(fml_dir, 'src', 'minecraft'), os.path.join(src_dir, 'minecraft')) + if has_server: + if os.path.isdir(os.path.join(fml_dir, 'patches', 'minecraft_server')): + apply_patches(os.path.join(fml_dir, 'patches', 'minecraft_server'), src_dir) + if os.path.isdir(os.path.join(fml_dir, 'src', 'minecraft_server')): + copytree(os.path.join(fml_dir, 'src', 'minecraft_server'), os.path.join(src_dir, 'minecraft_server')) + + os.chdir(mcp_dir) + updatenames(None, True) + reset_logger() + os.chdir(forge_dir) + + print 'Applying forge patches' + if has_client: + if os.path.isdir(os.path.join(forge_dir, 'patches', 'minecraft')): + apply_patches(os.path.join(forge_dir, 'patches', 'minecraft'), src_dir) + if os.path.isdir(os.path.join(forge_dir, 'src', 'minecraft')): + copytree(os.path.join(forge_dir, 'src', 'minecraft'), os.path.join(src_dir, 'minecraft')) + if has_server: + if os.path.isdir(os.path.join(forge_dir, 'patches', 'minecraft_server')): + apply_patches(os.path.join(forge_dir, 'patches', 'minecraft_server'), src_dir) + if os.path.isdir(os.path.join(forge_dir, 'src', 'minecraft_server')): + copytree(os.path.join(forge_dir, 'src', 'minecraft_server'), os.path.join(src_dir, 'minecraft_server')) + + os.chdir(mcp_dir) + updatemcp(None, True) + reset_logger() + updatenames(None, True) + reset_logger() + updatemd5(None, True) + reset_logger() + os.chdir(forge_dir) + + print '=================================== Minecraft Forge Setup Finished =================================' + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/forge/install/install.sh b/forge/install/install.sh index b33309233..07e01fcce 100644 --- a/forge/install/install.sh +++ b/forge/install/install.sh @@ -1,54 +1,2 @@ #!/bin/bash - -echo "MinecraftForge Linux Setup Program" -echo - -if [ ! -f ../runtime/bin/fernflower.jar ] -then - python download_fernflower.py -fi - -if [ ! -f ../runtime/bin/fernflower.jar ] -then - echo "Failed to download fernflower, install it manually and re-run setup." - exit 1 -fi - -pushd .. > /dev/null - -rm -rf conf -mkdir conf -cp -r forge/conf/* conf - -./cleanup.sh -if [ -d "src" ] -then - echo "Failed to cleanup the MCP folder, please backup your modified files and run this script again and say yes when promped." - exit 1 -fi -./decompile.sh - -pushd src > /dev/null - if [ -f ../jars/bin/minecraft.jar ]; - then - for i in `find ../forge/patches/minecraft/ -type f` - do - patch -p2 -i $i - done - cp -r ../forge/src/minecraft/* minecraft - fi - - - if [ -f ../jars/minecraft_server.jar ]; - then - for i in `find ../forge/patches/minecraft_server/ -type f` - do - patch -p2 -i $i - done - cp -r ../forge/src/minecraft_server/* minecraft_server - fi -popd > /dev/null - -./updatemcp.sh -f -./updatenames.sh -f -./updatemd5.sh -f \ No newline at end of file +python install.py \ No newline at end of file diff --git a/forge/release.py b/forge/release.py index fee8ca8d7..c5f3ccc45 100644 --- a/forge/release.py +++ b/forge/release.py @@ -43,6 +43,10 @@ def main(): except SystemExit, e: print 'Reobfusicate Exception: %d ' % e.code error_level = e.code + + extract_fml_obfed() + version = load_version(build_num) + version_str = '%d.%d.%d.%d' % (version['major'], version['minor'], version['revision'], version['build']) out_folder = os.path.join(forge_dir, 'forge-%s' % version_str) if os.path.isdir(out_folder): @@ -50,10 +54,6 @@ def main(): 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') @@ -66,6 +66,7 @@ def main(): zip_add('license.txt') zip_end() + inject_version(os.path.join(forge_dir, 'forge_common', 'net', 'minecraft', 'src', 'forge', 'ForgeHooks.java'), build_num) zip_start('minecraftforge-src-%s.zip' % version_str, 'forge') zip_add('forge_client/src', 'src/minecraft') zip_add('forge_server/src', 'src/minecraft_server') @@ -80,9 +81,9 @@ def main(): 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() + inject_version(os.path.join(forge_dir, 'forge_common', 'net', 'minecraft', 'src', 'forge', 'ForgeHooks.java'), 0) print '=================================== Release Finished %d =================================' % error_level sys.exit(error_level)