ForgePatch/fml/bukkit/net/minecraft/server/BukkitRegistry.java

165 lines
5.5 KiB
Java
Raw Normal View History

2012-04-15 03:01:03 +00:00
package net.minecraft.server;
2012-06-20 16:36:48 +00:00
import java.util.Iterator;
2012-04-15 03:01:03 +00:00
import java.util.List;
import net.minecraft.src.BiomeGenBase;
import cpw.mods.fml.common.registry.IMinecraftRegistry;
2012-06-01 04:27:46 +00:00
import cpw.mods.fml.server.FMLBukkitHandler;
2012-04-15 03:01:03 +00:00
public class BukkitRegistry implements IMinecraftRegistry
{
@Override
public void addRecipe(net.minecraft.src.ItemStack output, Object... params)
2012-04-15 03:01:03 +00:00
{
CraftingManager.getInstance().registerShapedRecipe((ItemStack) output, params);
2012-04-15 03:01:03 +00:00
}
@Override
public void addShapelessRecipe(net.minecraft.src.ItemStack output, Object... params)
2012-04-15 03:01:03 +00:00
{
CraftingManager.getInstance().registerShapelessRecipe((ItemStack) output, params);
2012-04-15 03:01:03 +00:00
}
@SuppressWarnings("unchecked")
@Override
public void addRecipe(net.minecraft.src.IRecipe recipe)
{
CraftingManager.getInstance().getRecipies().add(recipe);
}
2012-04-15 03:01:03 +00:00
@Override
public void addSmelting(int input, net.minecraft.src.ItemStack output)
2012-04-15 03:01:03 +00:00
{
FurnaceRecipes.getInstance().registerRecipe(input, (ItemStack) output);
2012-04-15 03:01:03 +00:00
}
@Override
public void registerBlock(net.minecraft.src.Block block)
2012-04-15 03:01:03 +00:00
{
registerBlock(block, ItemBlock.class);
}
@Override
public void registerBlock(net.minecraft.src.Block block, Class <? extends net.minecraft.src.ItemBlock > itemclass)
2012-04-15 03:01:03 +00:00
{
try
{
assert block != null : "registerBlock: block cannot be null";
assert itemclass != null : "registerBlock: itemclass cannot be null";
int blockItemId = ((Block)block).id - 256;
2012-04-15 03:01:03 +00:00
itemclass.getConstructor(int.class).newInstance(blockItemId);
}
catch (Exception e)
{
//HMMM
}
}
@SuppressWarnings("unchecked")
@Override
public void registerEntityID(Class <? extends net.minecraft.src.Entity > entityClass, String entityName, int id)
2012-04-15 03:01:03 +00:00
{
EntityTypes.addNewEntityListMapping((Class<? extends Entity>) entityClass, entityName, id);
2012-04-15 03:01:03 +00:00
}
@SuppressWarnings("unchecked")
@Override
public void registerEntityID(Class <? extends net.minecraft.src.Entity > entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)
2012-04-15 03:01:03 +00:00
{
EntityTypes.addNewEntityListMapping((Class<? extends Entity>) entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
2012-04-15 03:01:03 +00:00
}
@SuppressWarnings("unchecked")
@Override
public void registerTileEntity(Class <? extends net.minecraft.src.TileEntity > tileEntityClass, String id)
2012-04-15 03:01:03 +00:00
{
TileEntity.addNewTileEntityMapping((Class<? extends TileEntity>) tileEntityClass, id);
2012-04-15 03:01:03 +00:00
}
@Override
public void addBiome(BiomeGenBase biome)
2012-04-15 03:01:03 +00:00
{
2012-06-01 04:27:46 +00:00
FMLBukkitHandler.instance().addBiomeToDefaultWorldGenerator((BiomeBase) biome);
2012-04-15 03:01:03 +00:00
}
@Override
public void addSpawn(Class <? extends net.minecraft.src.EntityLiving > entityClass, int weightedProb, int min, int max, net.minecraft.src.EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
2012-04-15 03:01:03 +00:00
{
BiomeBase[] realBiomes=(BiomeBase[]) biomes;
for (BiomeBase biome : realBiomes)
{
@SuppressWarnings("unchecked")
List<BiomeMeta> spawns = ((BiomeBase)biome).getMobs((EnumCreatureType)typeOfCreature);
2012-04-15 03:01:03 +00:00
for (BiomeMeta entry : spawns)
{
//Adjusting an existing spawn entry
if (entry.a == entityClass)
{
entry.d = weightedProb;
entry.b = min;
entry.c = max;
break;
}
}
2012-04-15 03:01:03 +00:00
spawns.add(new BiomeMeta(entityClass, weightedProb, min, max));
}
}
@Override
@SuppressWarnings("unchecked")
public void addSpawn(String entityName, int weightedProb, int min, int max, net.minecraft.src.EnumCreatureType spawnList, BiomeGenBase... biomes)
2012-04-15 03:01:03 +00:00
{
Class <? extends Entity > entityClazz = EntityTypes.getEntityToClassMapping().get(entityName);
2012-04-15 03:01:03 +00:00
if (EntityLiving.class.isAssignableFrom(entityClazz))
{
addSpawn((Class <? extends net.minecraft.src.EntityLiving >) entityClazz, weightedProb, min, max, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
}
@Override
public void removeBiome(BiomeGenBase biome)
2012-04-15 03:01:03 +00:00
{
2012-06-09 14:47:43 +00:00
FMLBukkitHandler.instance().removeBiomeFromDefaultWorldGenerator((BiomeBase)biome);
2012-04-15 03:01:03 +00:00
}
@Override
public void removeSpawn(Class <? extends net.minecraft.src.EntityLiving > entityClass, net.minecraft.src.EnumCreatureType typeOfCreature, BiomeGenBase... biomesO)
2012-04-15 03:01:03 +00:00
{
BiomeBase[] biomes=(BiomeBase[]) biomesO;
for (BiomeBase biome : biomes)
{
@SuppressWarnings("unchecked")
List<BiomeMeta> spawns = ((BiomeBase)biome).getMobs((EnumCreatureType) typeOfCreature);
2012-06-20 16:36:48 +00:00
Iterator<BiomeMeta> entries = spawns.iterator();
while (entries.hasNext())
2012-04-15 03:01:03 +00:00
{
2012-06-20 16:36:48 +00:00
BiomeMeta entry = entries.next();
2012-04-15 03:01:03 +00:00
if (entry.a == entityClass)
{
2012-06-20 16:36:48 +00:00
entries.remove();
2012-04-15 03:01:03 +00:00
}
}
}
}
@Override
@SuppressWarnings("unchecked")
public void removeSpawn(String entityName, net.minecraft.src.EnumCreatureType spawnList, BiomeGenBase... biomes)
2012-04-15 03:01:03 +00:00
{
Class <? extends Entity > entityClazz = EntityTypes.getEntityToClassMapping().get(entityName);
2012-04-15 03:01:03 +00:00
if (EntityLiving.class.isAssignableFrom(entityClazz))
{
removeSpawn((Class <? extends net.minecraft.src.EntityLiving >) entityClazz, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
}
}