Moved in OreDictionary stuff to new system. IOreHandler is replaced by OreDictionary.OreRegisterEvent
This commit is contained in:
parent
bd93dd58d0
commit
bb0f84925e
7 changed files with 25 additions and 409 deletions
|
@ -1,4 +1,4 @@
|
||||||
package net.minecraft.src.forge.oredict;
|
package net.minecraftforge.oredict;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -10,14 +10,14 @@ import java.util.Map.Entry;
|
||||||
import net.minecraft.src.Block;
|
import net.minecraft.src.Block;
|
||||||
import net.minecraft.src.Item;
|
import net.minecraft.src.Item;
|
||||||
import net.minecraft.src.ItemStack;
|
import net.minecraft.src.ItemStack;
|
||||||
import net.minecraft.src.forge.IOreHandler;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.Event;
|
||||||
|
|
||||||
public class OreDictionary
|
public class OreDictionary
|
||||||
{
|
{
|
||||||
private static int maxID = 0;
|
private static int maxID = 0;
|
||||||
private static HashMap<String, Integer> oreIDs = new HashMap<String, Integer>();
|
private static HashMap<String, Integer> oreIDs = new HashMap<String, Integer>();
|
||||||
private static HashMap<Integer, ArrayList<ItemStack>> oreStacks = new HashMap<Integer, ArrayList<ItemStack>>();
|
private static HashMap<Integer, ArrayList<ItemStack>> oreStacks = new HashMap<Integer, ArrayList<ItemStack>>();
|
||||||
private static ArrayList<IOreHandler> oreHandlers = new ArrayList<IOreHandler>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the integer ID for the specified ore name.
|
* Gets the integer ID for the specified ore name.
|
||||||
|
@ -68,6 +68,16 @@ public class OreDictionary
|
||||||
return getOres(getOreID(name));
|
return getOres(getOreID(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a list of all unique ore names that are already registered.
|
||||||
|
*
|
||||||
|
* @return All unique ore names that are currently registered.
|
||||||
|
*/
|
||||||
|
public static String[] getOreNames()
|
||||||
|
{
|
||||||
|
return oreIDs.keySet().toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the ArrayList of items that are registered to this ore type.
|
* Retrieves the ArrayList of items that are registered to this ore type.
|
||||||
* Creates the list as empty if it did not exist.
|
* Creates the list as empty if it did not exist.
|
||||||
|
@ -86,28 +96,6 @@ public class OreDictionary
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new ore handler.
|
|
||||||
* This will automatically call the handler with all current ores during
|
|
||||||
* registration, and every time a new ore is added later.
|
|
||||||
*
|
|
||||||
* @param handler The Ore Handler
|
|
||||||
*/
|
|
||||||
public static void registerOreHandler(IOreHandler handler)
|
|
||||||
{
|
|
||||||
oreHandlers.add(handler);
|
|
||||||
|
|
||||||
HashMap<String, Integer> tmp = (HashMap<String, Integer>)oreIDs.clone();
|
|
||||||
|
|
||||||
for(Map.Entry<String, Integer> entry : tmp.entrySet())
|
|
||||||
{
|
|
||||||
for(ItemStack stack : getOres(entry.getValue()))
|
|
||||||
{
|
|
||||||
handler.registerOre(entry.getKey(), stack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
|
//Convenience functions that make for cleaner code mod side. They all drill down to registerOre(String, int, ItemStack)
|
||||||
public static void registerOre(String name, Item ore){ registerOre(name, new ItemStack(ore)); }
|
public static void registerOre(String name, Item ore){ registerOre(name, new ItemStack(ore)); }
|
||||||
public static void registerOre(String name, Block ore){ registerOre(name, new ItemStack(ore)); }
|
public static void registerOre(String name, Block ore){ registerOre(name, new ItemStack(ore)); }
|
||||||
|
@ -129,10 +117,18 @@ public class OreDictionary
|
||||||
ArrayList<ItemStack> ores = getOres(id);
|
ArrayList<ItemStack> ores = getOres(id);
|
||||||
ore = ore.copy();
|
ore = ore.copy();
|
||||||
ores.add(ore);
|
ores.add(ore);
|
||||||
|
MinecraftForge.eventBus.post(new OreRegisterEvent(name, ore));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OreRegisterEvent extends Event
|
||||||
|
{
|
||||||
|
public final String Name;
|
||||||
|
public final ItemStack Ore;
|
||||||
|
|
||||||
for (IOreHandler handler : oreHandlers)
|
public OreRegisterEvent(String name, ItemStack ore)
|
||||||
{
|
{
|
||||||
handler.registerOre(name, ore);
|
this.Name = name;
|
||||||
|
this.Ore = ore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package net.minecraft.src.forge.oredict;
|
package net.minecraftforge.oredict;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
||||||
package net.minecraft.src.forge.oredict;
|
package net.minecraftforge.oredict;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
|
@ -1,24 +0,0 @@
|
||||||
/**
|
|
||||||
* This software is provided under the terms of the Minecraft Forge Public
|
|
||||||
* License v1.0.
|
|
||||||
*/
|
|
||||||
package net.minecraft.src.forge;
|
|
||||||
|
|
||||||
import net.minecraft.src.EntityPlayer;
|
|
||||||
import net.minecraft.src.ItemStack;
|
|
||||||
import net.minecraft.src.World;
|
|
||||||
|
|
||||||
public interface IArrowLooseHandler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* This is called before a bow tries to shoot an arrow. If it
|
|
||||||
* returns a true result, then the normal arrow will not be shot.
|
|
||||||
*
|
|
||||||
* @param itemstack The ItemStack for the bow doing the firing
|
|
||||||
* @param world The current world
|
|
||||||
* @param player The player that is firing the bow
|
|
||||||
* @param heldTime The amount of ticks the bow was held ready.
|
|
||||||
* @return True if the event should be canceled.
|
|
||||||
*/
|
|
||||||
public boolean onArrowLoose(ItemStack itemstack, World world, EntityPlayer player, int heldTime);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/**
|
|
||||||
* This software is provided under the terms of the Minecraft Forge Public
|
|
||||||
* License v1.0.
|
|
||||||
*/
|
|
||||||
package net.minecraft.src.forge;
|
|
||||||
|
|
||||||
import net.minecraft.src.ItemStack;
|
|
||||||
import net.minecraft.src.World;
|
|
||||||
import net.minecraft.src.EntityPlayer;
|
|
||||||
|
|
||||||
public interface IArrowNockHandler
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called before a player tries to load an arrow. If it returns
|
|
||||||
* a non-null result, then the normal arrow will not be loaded and the
|
|
||||||
* bow will be changed to the returned value.
|
|
||||||
*
|
|
||||||
* @param itemstack The ItemStack for the bow doing the firing
|
|
||||||
* @param world The current world
|
|
||||||
* @param player The player that is using the bow
|
|
||||||
* @return The new bow item, or null to continue normally.
|
|
||||||
*/
|
|
||||||
public ItemStack onArrowNock(ItemStack itemstack, World world, EntityPlayer player);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/**
|
|
||||||
* This software is provided under the terms of the Minecraft Forge Public
|
|
||||||
* License v1.0.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.minecraft.src.forge;
|
|
||||||
|
|
||||||
import net.minecraft.src.ItemStack;
|
|
||||||
|
|
||||||
/** The current list of known classes.
|
|
||||||
* oreTin, oreCopper, oreSilver, oreUranium
|
|
||||||
* ingotTin, ingotCopper, ingotSilver, ingotBrass, ingotBronze
|
|
||||||
* ingotUranium, ingotRefinedIron
|
|
||||||
* dyeBlue
|
|
||||||
* gemRuby, gemEmerald, gemSapphire
|
|
||||||
* itemDropUranium
|
|
||||||
* woodRubber
|
|
||||||
* itemRubber
|
|
||||||
*/
|
|
||||||
|
|
||||||
public interface IOreHandler
|
|
||||||
{
|
|
||||||
/** Called when a new ore is registered with the ore dictionary.
|
|
||||||
* @param oreClass The string class of the ore.
|
|
||||||
* @param ore The ItemStack for the ore.
|
|
||||||
*/
|
|
||||||
public void registerOre(String oreClass, ItemStack ore);
|
|
||||||
}
|
|
|
@ -28,308 +28,6 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
public class MinecraftForge
|
public class MinecraftForge
|
||||||
{
|
{
|
||||||
private static LinkedList<IBucketHandler> bucketHandlers = new LinkedList<IBucketHandler>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new custom bucket handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerCustomBucketHandler(IBucketHandler handler)
|
|
||||||
{
|
|
||||||
bucketHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new sleeping handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerSleepHandler(ISleepHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.sleepHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new bonemeal handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerBonemealHandler(IBonemealHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.bonemealHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new hoe handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerHoeHandler(IHoeHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.hoeHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new destroy tool handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerDestroyToolHandler(IDestroyToolHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.destroyToolHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new crafting handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerCraftingHandler(ICraftingHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.craftingHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new minecart handler
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerMinecartHandler(IMinecartHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.minecartHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new Connection event handler
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerConnectionHandler(IConnectionHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.connectionHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new Chunk Load event handler
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerChunkLoadHandler(IChunkLoadHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.chunkLoadHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new Item Pickup event handler
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerPickupHandler(IPickupHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.pickupHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new entity interact handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerEntityInteractHandler(IEntityInteractHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.entityInteractHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a new chat handler.
|
|
||||||
* @param handler The Handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerChatHandler(IChatHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.chatHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new Save handler
|
|
||||||
* @param handler The handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerSaveHandler(ISaveEventHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.saveHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new Fuel handler
|
|
||||||
* @param handler The handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerFuelHandler(IFuelHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.fuelHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new Special Mob Spawn handler
|
|
||||||
* @param handler The handler to be registered
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static void registerSpecialMobSpawnHandler(ISpecialMobSpawnHandler handler)
|
|
||||||
{
|
|
||||||
if (EntityLiving.class.getPackage() != null)
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Still using deprecated method/interface MinecraftForge.registerSpecialModSpawnHandler()");
|
|
||||||
}
|
|
||||||
ForgeHooks.specialMobSpawnHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a new EntityLiving Handler
|
|
||||||
* @param handler The handler to be registered
|
|
||||||
*/
|
|
||||||
public static void registerEntityLivingHandler(IEntityLivingHandler handler)
|
|
||||||
{
|
|
||||||
ForgeHooks.entityLivingHandlers.add(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is not supposed to be called outside of Minecraft internals.
|
|
||||||
*/
|
|
||||||
public static ItemStack fillCustomBucket(World world, int X, int Y, int Z)
|
|
||||||
{
|
|
||||||
for (IBucketHandler handler : bucketHandlers)
|
|
||||||
{
|
|
||||||
ItemStack stack = handler.fillCustomBucket(world, X, Y, Z);
|
|
||||||
|
|
||||||
if (stack != null)
|
|
||||||
{
|
|
||||||
return stack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ore Dictionary
|
|
||||||
// ------------------------------------------------------------
|
|
||||||
//Deprecated in favor of OreDictionary.registerOreHandler
|
|
||||||
@Deprecated
|
|
||||||
public static void registerOreHandler(IOreHandler handler)
|
|
||||||
{
|
|
||||||
OreDictionary.registerOreHandler(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Deprecated in favor of OreDictionary.registerOre
|
|
||||||
@Deprecated
|
|
||||||
public static void registerOre(String oreClass, ItemStack ore)
|
|
||||||
{
|
|
||||||
OreDictionary.registerOre(oreClass, ore);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Deprecated in favor of OreDictionary.getOres
|
|
||||||
@Deprecated
|
|
||||||
public static List<ItemStack> getOreClass(String oreClass)
|
|
||||||
{
|
|
||||||
return OreDictionary.getOres(oreClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Deprecated in favor of the Ore recipes, and because it is ugly as heck.
|
|
||||||
@Deprecated
|
|
||||||
public static class OreQuery implements Iterable<Object[]>
|
|
||||||
{
|
|
||||||
Object[] proto;
|
|
||||||
|
|
||||||
public class OreQueryIterator implements Iterator<Object[]>
|
|
||||||
{
|
|
||||||
LinkedList itering = new LinkedList();
|
|
||||||
LinkedList output = new LinkedList();
|
|
||||||
|
|
||||||
private OreQueryIterator()
|
|
||||||
{
|
|
||||||
for (Object input : proto)
|
|
||||||
{
|
|
||||||
if (input instanceof Collection)
|
|
||||||
{
|
|
||||||
Iterator it = ((Collection)input).iterator();
|
|
||||||
if (!it.hasNext())
|
|
||||||
{
|
|
||||||
output = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
itering.addLast(it);
|
|
||||||
output.addLast(it.next());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
itering.addLast(input);
|
|
||||||
output.addLast(input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNext()
|
|
||||||
{
|
|
||||||
return output != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object[] next()
|
|
||||||
{
|
|
||||||
Object[] tr = output.toArray();
|
|
||||||
Object to;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (itering.size() == 0)
|
|
||||||
{
|
|
||||||
output = null;
|
|
||||||
return tr;
|
|
||||||
}
|
|
||||||
to = itering.getLast();
|
|
||||||
output.removeLast();
|
|
||||||
if (to instanceof Iterator)
|
|
||||||
{
|
|
||||||
Iterator it = (Iterator)to;
|
|
||||||
if (it.hasNext())
|
|
||||||
{
|
|
||||||
output.addLast(it.next());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
itering.removeLast();
|
|
||||||
}
|
|
||||||
for (int i = itering.size(); i < proto.length; i++)
|
|
||||||
{
|
|
||||||
if (proto[i] instanceof Collection)
|
|
||||||
{
|
|
||||||
Iterator it = ((Collection)proto[i]).iterator();
|
|
||||||
if (!it.hasNext())
|
|
||||||
{
|
|
||||||
output = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
itering.addLast(it);
|
|
||||||
output.addLast(it.next());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
itering.addLast(proto[i]);
|
|
||||||
output.addLast(proto[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tr;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
private OreQuery(Object[] pattern)
|
|
||||||
{
|
|
||||||
proto = pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterator<Object[]> iterator()
|
|
||||||
{
|
|
||||||
return new OreQueryIterator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Generate all valid legal recipe combinations. Any Lists in pattern
|
|
||||||
* will be fully expanded to all valid combinations.
|
|
||||||
*/
|
|
||||||
//Deprecated in favor of the new Ore Recipe system
|
|
||||||
@Deprecated
|
|
||||||
public static OreQuery generateRecipes(Object... pattern)
|
|
||||||
{
|
|
||||||
return new OreQuery(pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
/** Register a new plant to be planted when bonemeal is used on grass.
|
/** Register a new plant to be planted when bonemeal is used on grass.
|
||||||
|
|
Loading…
Reference in a new issue