diff --git a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java index d84ff671a..690a93a9a 100644 --- a/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java +++ b/forge/forge_common/net/minecraft/src/forge/ForgeHooks.java @@ -26,9 +26,9 @@ public class ForgeHooks { static LinkedList craftingHandlers = new LinkedList(); - public static void onDestroyCurrentItem(EntityPlayer player) { + public static void onDestroyCurrentItem(EntityPlayer player, ItemStack orig) { for (IDestroyToolHandler handler : destroyToolHandlers) { - handler.onDestroyCurrentItem(player); + handler.onDestroyCurrentItem(player,orig); } } @@ -138,6 +138,13 @@ public class ForgeHooks { // TODO: add other tool tables. } + public static final int majorVersion=1; + public static final int minorVersion=1; + public static final int revisionVersion=5; + static { + System.out.printf("MinecraftForge V%d.%d.%d Initialized\n",majorVersion,minorVersion,revisionVersion); + } + static boolean toolInit=false; static HashMap toolClasses=new HashMap(); static HashMap toolHarvestLevels=new HashMap(); diff --git a/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java b/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java index a69dd9954..07688e286 100644 --- a/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java +++ b/forge/forge_common/net/minecraft/src/forge/IDestroyToolHandler.java @@ -4,12 +4,13 @@ */ package net.minecraft.src.forge; +import net.minecraft.src.ItemStack; import net.minecraft.src.EntityPlayer; import net.minecraft.src.EnumStatus; public interface IDestroyToolHandler { /** Called when the user's currently equipped item is destroyed. */ - public void onDestroyCurrentItem(EntityPlayer player); + public void onDestroyCurrentItem(EntityPlayer player, ItemStack orig); } diff --git a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java index 9a70550b8..7458cb850 100755 --- a/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java +++ b/forge/forge_common/net/minecraft/src/forge/MinecraftForge.java @@ -166,4 +166,55 @@ public class MinecraftForge { public static void addPickaxeBlockEffectiveAgainst (Block block) { setBlockHarvestLevel(block,"pickaxe",0); } + + /** + * Kill minecraft with an error message. + */ + public static void killMinecraft(String modname, String msg) { + throw new RuntimeException(modname+": "+msg); + } + + /** + * Version checking. Ensures that a sufficiently recent version of Forge + * is installed. Will result in a fatal error if the major versions + * mismatch or if the version is too old. Will print a warning message if + * the minor versions don't match. + */ + public static void versionDetect(String modname, + int major, int minor, int revision) { + if(major!=ForgeHooks.majorVersion) { + killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x"); + } else if(minor!=ForgeHooks.minorVersion) { + if(minor>ForgeHooks.minorVersion) { + killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); + } else { + System.out.println(modname + ": MinecraftForge minor version mismatch, expecting "+major+"."+minor+".x, may lead to unexpected behavior"); + } + } else if(revision>ForgeHooks.revisionVersion) { + killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); + } + } + + /** + * Strict version checking. Ensures that a sufficiently recent version of + * Forge is installed. Will result in a fatal error if the major or minor + * versions mismatch or if the version is too old. Use this function for + * mods that use recent, new, or unstable APIs to prevent + * incompatibilities. + */ + public static void versionDetectStrict(String modname, + int major, int minor, int revision) { + if(major!=ForgeHooks.majorVersion) { + killMinecraft(modname,"MinecraftForge Major Version Mismatch, expecting "+major+".x.x"); + } else if(minor!=ForgeHooks.minorVersion) { + if(minor>ForgeHooks.minorVersion) { + killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); + } else { + killMinecraft(modname,"MinecraftForge minor version mismatch, expecting "+major+"."+minor+".x"); + } + } else if(revision>ForgeHooks.revisionVersion) { + killMinecraft(modname,"MinecraftForge Too Old, need at least "+major+"."+minor+"."+revision); + } + } + } diff --git a/forge/minecraft.patch b/forge/minecraft.patch index 68b19fa8c..bae16af76 100644 --- a/forge/minecraft.patch +++ b/forge/minecraft.patch @@ -956,7 +956,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/EntityLiv public void writeEntityToNBT(NBTTagCompound nbttagcompound) diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/EntityPlayer.java ../src_work/minecraft/net/minecraft/src/EntityPlayer.java --- ../src_base/minecraft/net/minecraft/src/EntityPlayer.java 2011-08-11 17:02:11.000000000 -0400 -+++ ../src_work/minecraft/net/minecraft/src/EntityPlayer.java 2011-08-17 19:06:38.000000000 -0400 ++++ ../src_work/minecraft/net/minecraft/src/EntityPlayer.java 2011-08-20 03:54:26.000000000 -0400 @@ -6,6 +6,9 @@ import java.util.*; @@ -1023,15 +1023,17 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/EntityPla int j = 25 - inventory.getTotalArmorValue(); int k = i * j + damageRemainder; inventory.damageArmor(i); -@@ -523,6 +561,7 @@ +@@ -522,7 +560,9 @@ + public void destroyCurrentEquippedItem() { ++ ItemStack orig=inventory.getCurrentItem(); inventory.setInventorySlotContents(inventory.currentItem, null); -+ ForgeHooks.onDestroyCurrentItem(this); ++ ForgeHooks.onDestroyCurrentItem(this,orig); } public double getYOffset() -@@ -594,6 +633,10 @@ +@@ -594,6 +634,10 @@ public EnumStatus sleepInBedAt(int i, int j, int k) { @@ -1186,7 +1188,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/MovingObj } diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/PlayerController.java ../src_work/minecraft/net/minecraft/src/PlayerController.java --- ../src_base/minecraft/net/minecraft/src/PlayerController.java 2011-08-11 17:02:11.000000000 -0400 -+++ ../src_work/minecraft/net/minecraft/src/PlayerController.java 2011-08-17 20:02:41.000000000 -0400 ++++ ../src_work/minecraft/net/minecraft/src/PlayerController.java 2011-08-20 03:56:00.000000000 -0400 @@ -3,6 +3,7 @@ // Decompiler options: packimports(3) braces deadcode @@ -1199,7 +1201,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/PlayerCon if(itemstack1.stackSize == 0) { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; -+ ForgeHooks.onDestroyCurrentItem(entityplayer); ++ ForgeHooks.onDestroyCurrentItem(entityplayer,itemstack1); } return true; } else @@ -1224,7 +1226,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft/net/minecraft/src/PlayerCon + if(!itemstack.useItem(entityplayer, world, i, j, k, l)) + return false; + if(itemstack.stackSize == 0) -+ ForgeHooks.onDestroyCurrentItem(entityplayer); ++ ForgeHooks.onDestroyCurrentItem(entityplayer,itemstack); + return true; } } @@ -2632,7 +2634,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/En public void writeEntityToNBT(NBTTagCompound nbttagcompound) diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/EntityPlayer.java ../src_work/minecraft_server/net/minecraft/src/EntityPlayer.java --- ../src_base/minecraft_server/net/minecraft/src/EntityPlayer.java 2011-08-11 17:02:12.000000000 -0400 -+++ ../src_work/minecraft_server/net/minecraft/src/EntityPlayer.java 2011-08-17 19:06:41.000000000 -0400 ++++ ../src_work/minecraft_server/net/minecraft/src/EntityPlayer.java 2011-08-20 03:53:18.000000000 -0400 @@ -6,6 +6,9 @@ import java.util.*; @@ -2699,15 +2701,17 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/En int j = 25 - inventory.getTotalArmorValue(); int k = i * j + damageRemainder; inventory.damageArmor(i); -@@ -503,6 +541,7 @@ +@@ -502,7 +540,9 @@ + public void destroyCurrentEquippedItem() { ++ ItemStack orig=inventory.getCurrentItem(); inventory.setInventorySlotContents(inventory.currentItem, null); -+ ForgeHooks.onDestroyCurrentItem(this); ++ ForgeHooks.onDestroyCurrentItem(this,orig); } public double getYOffset() -@@ -568,6 +607,10 @@ +@@ -568,6 +608,10 @@ public EnumStatus goToSleep(int i, int j, int k) { @@ -2775,7 +2779,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/It world.setBlockWithNotify(i, j, k, 0); diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/ItemInWorldManager.java ../src_work/minecraft_server/net/minecraft/src/ItemInWorldManager.java --- ../src_base/minecraft_server/net/minecraft/src/ItemInWorldManager.java 2011-08-11 17:02:12.000000000 -0400 -+++ ../src_work/minecraft_server/net/minecraft/src/ItemInWorldManager.java 2011-08-17 20:02:48.000000000 -0400 ++++ ../src_work/minecraft_server/net/minecraft/src/ItemInWorldManager.java 2011-08-20 03:56:01.000000000 -0400 @@ -3,6 +3,7 @@ // Decompiler options: packimports(3) braces deadcode @@ -2825,7 +2829,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/It if(itemstack1.stackSize == 0) { entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; -+ ForgeHooks.onDestroyCurrentItem(entityplayer); ++ ForgeHooks.onDestroyCurrentItem(entityplayer,itemstack1); } return true; } else @@ -2849,7 +2853,7 @@ diff -u -r --strip-trailing-cr ../src_base/minecraft_server/net/minecraft/src/It + if(!itemstack.useItem(entityplayer, world, i, j, k, l)) + return false; + if(itemstack.stackSize == 0) -+ ForgeHooks.onDestroyCurrentItem(entityplayer); ++ ForgeHooks.onDestroyCurrentItem(entityplayer,itemstack); + return true; } }