Fix compatibility with ModLoader dispenser hook. Fixes a bug with

IDispenseHandler too - though it means that interface is now
deprecated
This commit is contained in:
Christian 2012-09-03 11:37:17 -04:00
parent 5bea2a0bbd
commit 2af15b3a95
8 changed files with 66 additions and 18 deletions

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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<IWorldGenerator> worldGenerators = Sets.newHashSet();
private static List<IFuelHandler> fuelHandlers = Lists.newArrayList();
private static List<ICraftingHandler> craftingHandlers = Lists.newArrayList();
private static List<IDispenseHandler> dispenserHandlers = Lists.newArrayList();
private static List<IDispenserHandler> dispenserHandlers = Lists.newArrayList();
private static List<IPickupNotifier> pickupHandlers = Lists.newArrayList();
private static List<IPlayerTracker> 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)

View file

@ -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;