From 2af15b3a95f4581879f479b1f08ab529e44eae8d Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 3 Sep 2012 11:37:17 -0400 Subject: [PATCH] Fix compatibility with ModLoader dispenser hook. Fixes a bug with IDispenseHandler too - though it means that interface is now deprecated --- fml/client/net/minecraft/src/BaseMod.java | 2 +- .../cpw/mods/fml/common/IDispenseHandler.java | 3 +- .../mods/fml/common/IDispenserHandler.java | 30 ++++++++++++++++ .../fml/common/modloader/BaseModProxy.java | 2 +- .../modloader/ModLoaderDispenseHelper.java | 8 +++-- .../fml/common/modloader/ModLoaderHelper.java | 3 +- .../fml/common/registry/GameRegistry.java | 34 +++++++++++++------ .../minecraft/src/BlockDispenser.java.patch | 2 +- 8 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 fml/common/cpw/mods/fml/common/IDispenserHandler.java diff --git a/fml/client/net/minecraft/src/BaseMod.java b/fml/client/net/minecraft/src/BaseMod.java index a7993c290..4a9604fde 100644 --- a/fml/client/net/minecraft/src/BaseMod.java +++ b/fml/client/net/minecraft/src/BaseMod.java @@ -196,7 +196,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr * @return */ @Override - public int dispenseEntity(World world, ItemStack item, Random rnd, double x, double y, double z, int xVel, int zVel, double entX, double entY, double entZ) + public int dispenseEntity(World world, ItemStack item, Random rnd, int x, int y, int z, int xVel, int zVel, double entX, double entY, double entZ) { return -1; } diff --git a/fml/common/cpw/mods/fml/common/IDispenseHandler.java b/fml/common/cpw/mods/fml/common/IDispenseHandler.java index dcb053d2c..bb8ab35b4 100644 --- a/fml/common/cpw/mods/fml/common/IDispenseHandler.java +++ b/fml/common/cpw/mods/fml/common/IDispenseHandler.java @@ -23,7 +23,7 @@ public interface IDispenseHandler /** * Return -1 if you don't want to dispense anything. the other values seem to have specific meanings * to blockdispenser. - * + * * @param x * @param y * @param z @@ -37,5 +37,6 @@ public interface IDispenseHandler * @param entZ * @return */ + @Deprecated int dispense(double x, double y, double z, int xVelocity, int zVelocity, World world, ItemStack item, Random random, double entX, double entY, double entZ); } diff --git a/fml/common/cpw/mods/fml/common/IDispenserHandler.java b/fml/common/cpw/mods/fml/common/IDispenserHandler.java new file mode 100644 index 000000000..db59f5ad2 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/IDispenserHandler.java @@ -0,0 +1,30 @@ +package cpw.mods.fml.common; + +import java.util.Random; + +import net.minecraft.src.ItemStack; +import net.minecraft.src.World; + +/** + * @author cpw + * + */ +public interface IDispenserHandler +{ + /** + * Called to dispense an entity + * @param x + * @param y + * @param z + * @param xVelocity + * @param zVelocity + * @param world + * @param item + * @param random + * @param entX + * @param entY + * @param entZ + * @return + */ + int dispense(int x, int y, int z, int xVelocity, int zVelocity, World world, ItemStack item, Random random, double entX, double entY, double entZ); +} diff --git a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java index d6c2c2ea2..bc440ec67 100644 --- a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java +++ b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java @@ -89,7 +89,7 @@ public interface BaseModProxy public abstract void onItemPickup(EntityPlayer player, ItemStack item); - public abstract int dispenseEntity(World world, ItemStack item, Random rnd, double x, double y, double z, int xVel, int zVel, double entX, + public abstract int dispenseEntity(World world, ItemStack item, Random rnd, int x, int y, int z, int xVel, int zVel, double entX, double entY, double entZ); public abstract void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet); diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderDispenseHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderDispenseHelper.java index 0efb28e3d..1cc2a72bc 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderDispenseHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderDispenseHelper.java @@ -5,8 +5,9 @@ import java.util.Random; import net.minecraft.src.ItemStack; import net.minecraft.src.World; import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.IDispenserHandler; -public class ModLoaderDispenseHelper implements IDispenseHandler +public class ModLoaderDispenseHelper implements IDispenserHandler { private BaseModProxy mod; @@ -17,10 +18,11 @@ public class ModLoaderDispenseHelper implements IDispenseHandler } @Override - public int dispense(double x, double y, double z, int xVelocity, int zVelocity, World world, ItemStack item, Random random, double entX, double entY, + public int dispense(int x, int y, int z, int xVelocity, int zVelocity, World world, ItemStack item, Random random, double entX, double entY, double entZ) { - return mod.dispenseEntity(world, item, random, x, y, z, xVelocity, zVelocity, entX, entY, entZ); + int ret = mod.dispenseEntity(world, item, random, x, y, z, xVelocity, zVelocity, entX, entY, entZ); + return ret == 0 ? -1 : ret; } } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index 383bef7b2..dc86e62a9 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -34,6 +34,7 @@ import net.minecraft.src.TradeEntry; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.IDispenserHandler; import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; @@ -161,7 +162,7 @@ public class ModLoaderHelper return null; } - public static IDispenseHandler buildDispenseHelper(BaseModProxy mod) + public static IDispenserHandler buildDispenseHelper(BaseModProxy mod) { return new ModLoaderDispenseHelper(mod); } diff --git a/fml/common/cpw/mods/fml/common/registry/GameRegistry.java b/fml/common/cpw/mods/fml/common/registry/GameRegistry.java index 5336622c4..860e51a25 100644 --- a/fml/common/cpw/mods/fml/common/registry/GameRegistry.java +++ b/fml/common/cpw/mods/fml/common/registry/GameRegistry.java @@ -27,6 +27,7 @@ import com.google.common.collect.Sets; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.ICraftingHandler; import cpw.mods.fml.common.IDispenseHandler; +import cpw.mods.fml.common.IDispenserHandler; import cpw.mods.fml.common.IFuelHandler; import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IPlayerTracker; @@ -44,7 +45,7 @@ public class GameRegistry private static Set worldGenerators = Sets.newHashSet(); private static List fuelHandlers = Lists.newArrayList(); private static List craftingHandlers = Lists.newArrayList(); - private static List dispenserHandlers = Lists.newArrayList(); + private static List dispenserHandlers = Lists.newArrayList(); private static List pickupHandlers = Lists.newArrayList(); private static List playerTrackers = Lists.newArrayList(); @@ -82,14 +83,27 @@ public class GameRegistry } } + public static void registerDispenserHandler(IDispenserHandler handler) + { + dispenserHandlers.add(handler); + } /** * Register a handler for dispensers * * @param handler */ - public static void registerDispenserHandler(IDispenseHandler handler) + @Deprecated + public static void registerDispenserHandler(final IDispenseHandler handler) { - dispenserHandlers.add(handler); + registerDispenserHandler(new IDispenserHandler() + { + + @Override + public int dispense(int x, int y, int z, int xVelocity, int zVelocity, World world, ItemStack item, Random random, double entX, double entY, double entZ) + { + return handler.dispense(x, y, z, xVelocity, zVelocity, world, item, random, entX, entY, entZ); + } + }); } @@ -106,9 +120,9 @@ public class GameRegistry * @param item * @return */ - public static int tryDispense(World world, double x, double y, double z, int xVelocity, int zVelocity, ItemStack item, Random random, double entX, double entY, double entZ) + public static int tryDispense(World world, int x, int y, int z, int xVelocity, int zVelocity, ItemStack item, Random random, double entX, double entY, double entZ) { - for (IDispenseHandler handler : dispenserHandlers) + for (IDispenserHandler handler : dispenserHandlers) { int dispensed = handler.dispense(x, y, z, xVelocity, zVelocity, world, item, random, entX, entY, entZ); if (dispensed>-1) @@ -261,30 +275,30 @@ public class GameRegistry notify.notifyPickup(item, player); } } - + public static void registerPlayerTracker(IPlayerTracker tracker) { playerTrackers.add(tracker); } - + public static void onPlayerLogin(EntityPlayer player) { for(IPlayerTracker tracker : playerTrackers) tracker.onPlayerLogin(player); } - + public static void onPlayerLogout(EntityPlayer player) { for(IPlayerTracker tracker : playerTrackers) tracker.onPlayerLogout(player); } - + public static void onPlayerChangedDimension(EntityPlayer player) { for(IPlayerTracker tracker : playerTrackers) tracker.onPlayerChangedDimension(player); } - + public static void onPlayerRespawn(EntityPlayer player) { for(IPlayerTracker tracker : playerTrackers) diff --git a/fml/patches/common/net/minecraft/src/BlockDispenser.java.patch b/fml/patches/common/net/minecraft/src/BlockDispenser.java.patch index de49d8a1e..42b873559 100644 --- a/fml/patches/common/net/minecraft/src/BlockDispenser.java.patch +++ b/fml/patches/common/net/minecraft/src/BlockDispenser.java.patch @@ -14,7 +14,7 @@ float var15 = 1.1F; byte var16 = 6; - -+ int modDispense = GameRegistry.tryDispense(p_72283_1_, p_72283_9_, p_72283_11_, p_72283_13_, p_72283_7_, p_72283_8_, p_72283_2_, p_72283_3_, p_72283_9_, p_72283_11_, p_72283_13_); ++ int modDispense = GameRegistry.tryDispense(p_72283_1_, p_72283_4_, p_72283_5_, p_72283_6_, p_72283_7_, p_72283_8_, p_72283_2_, p_72283_3_, p_72283_9_, p_72283_11_, p_72283_13_); + if (modDispense > -1) + { + return modDispense;