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

780 lines
20 KiB
Java
Raw Normal View History

2012-04-15 03:01:03 +00:00
/*
* The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraft.server;
import java.util.List;
2012-06-01 04:27:46 +00:00
import java.util.Map;
2012-04-15 03:01:03 +00:00
import java.util.logging.Logger;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ReflectionHelper;
import cpw.mods.fml.common.modloader.ModLoaderHelper;
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
import cpw.mods.fml.common.registry.FMLRegistry;
2012-04-15 03:01:03 +00:00
import cpw.mods.fml.server.FMLBukkitHandler;
public class ModLoader
{
/**
* Not used on the server.
*
* @param achievement
* @param name
* @param description
*/
public static void addAchievementDesc(Achievement achievement, String name, String description)
{
2012-06-01 04:27:46 +00:00
String achName=achievement.getName();
addLocalization(achName, name);
addLocalization(achName+".desc", description);
2012-04-15 03:01:03 +00:00
}
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
*
2012-06-01 04:27:46 +00:00
* {@link FMLCommonHandler#fuelLookup(int, int)}
*
2012-04-15 03:01:03 +00:00
* @param id
* @param metadata
* @return
*/
@Deprecated
public static int addAllFuel(int id, int metadata)
{
return 0;
}
2012-06-01 04:27:46 +00:00
public static void addAllRenderers(Map<Class<? extends Entity>, Object> renderers)
{
}
public static void addAnimation(Object anim)
{
}
2012-04-15 03:01:03 +00:00
/**
* This method is unimplemented in server versions to date.
*
* @param armor
* @return
*/
public static int addArmor(String armor)
{
return 0;
}
/**
2012-06-01 04:27:46 +00:00
* This method adds the supplied biome to the set of candidate biomes for the default world generator type.
2012-04-15 03:01:03 +00:00
*
* @param biome
*/
public static void addBiome(BiomeBase biome)
{
2012-06-01 04:27:46 +00:00
FMLRegistry.addBiome(biome);
2012-04-15 03:01:03 +00:00
}
/**
2012-06-01 04:27:46 +00:00
* Add localization for the specified string
*
2012-04-15 03:01:03 +00:00
* @param key
* @param value
*/
public static void addLocalization(String key, String value)
{
2012-06-01 04:27:46 +00:00
addLocalization(key, "en_US", value);
2012-04-15 03:01:03 +00:00
}
/**
2012-06-01 04:27:46 +00:00
* Add localization for the specified string
*
2012-04-15 03:01:03 +00:00
* @param key
* @param lang
* @param value
*/
public static void addLocalization(String key, String lang, String value)
{
2012-06-01 04:27:46 +00:00
FMLCommonHandler.instance().addStringLocalization(key, lang, value);
2012-04-15 03:01:03 +00:00
}
/**
2012-06-01 04:27:46 +00:00
* Name the specified minecraft object with the supplied name
*
2012-04-15 03:01:03 +00:00
* @param instance
* @param name
*/
public static void addName(Object instance, String name)
{
2012-06-01 04:27:46 +00:00
addName(instance,"en_US",name);
2012-04-15 03:01:03 +00:00
}
/**
* Unimplemented on the server as it does not generate names
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param instance
* @param lang
* @param name
*/
public static void addName(Object instance, String lang, String name)
{
2012-06-01 04:27:46 +00:00
FMLCommonHandler.instance().addNameForObject(instance, lang, name);
2012-04-15 03:01:03 +00:00
}
/**
* Unimplemented on the server as it does not render textures
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param fileToOverride
* @param fileToAdd
* @return
*/
public static int addOverride(String fileToOverride, String fileToAdd)
{
return 0;
}
/**
* Unimplemented on the server as it does not render textures
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param path
* @param overlayPath
* @param index
*/
public static void addOverride(String path, String overlayPath, int index)
{
2012-06-01 04:27:46 +00:00
// NOOP
2012-04-15 03:01:03 +00:00
}
/**
* Add a Shaped Recipe
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param output
* @param params
*/
public static void addRecipe(ItemStack output, Object... params)
{
FMLRegistry.addRecipe(output, params);
2012-04-15 03:01:03 +00:00
}
/**
* Add a shapeless recipe
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param output
* @param params
*/
public static void addShapelessRecipe(ItemStack output, Object... params)
{
FMLRegistry.addShapelessRecipe(output, params);
2012-04-15 03:01:03 +00:00
}
/**
* Add a new product to be smelted
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param input
* @param output
*/
public static void addSmelting(int input, ItemStack output)
{
FMLRegistry.addSmelting(input, output);
2012-04-15 03:01:03 +00:00
}
/**
* Add a mob to the spawn list
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityClass
* @param weightedProb
* @param min
* @param max
* @param spawnList
*/
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList)
{
FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLBukkitHandler.instance().getDefaultOverworldBiomes());
2012-04-15 03:01:03 +00:00
}
/**
* Add a mob to the spawn list
* @param entityClass
* @param weightedProb
* @param min
* @param max
* @param spawnList
* @param biomes
*/
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeBase... biomes)
{
FMLRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
/**
* Add a mob to the spawn list
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityName
* @param weightedProb
* @param min
* @param max
* @param spawnList
*/
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList)
{
FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLBukkitHandler.instance().getDefaultOverworldBiomes());
2012-04-15 03:01:03 +00:00
}
/**
* Add a mob to the spawn list
* @param entityName
* @param weightedProb
* @param min
* @param max
* @param spawnList
* @param biomes
*/
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeBase... biomes)
{
FMLRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLBukkitHandler#tryDispensingEntity(World, double, double, double, byte, byte, ItemStack)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param world
* @param x
* @param y
* @param z
* @param xVel
* @param zVel
* @param item
* @return
*/
@Deprecated
public static boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item)
{
return false;
}
/**
* Remove a container and drop all the items in it on the ground around
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param world
* @param x
* @param y
* @param z
*/
public static void genericContainerRemoval(World world, int x, int y, int z)
{
TileEntity te = world.getTileEntity(x, y, z);
if (!(te instanceof IInventory))
{
return;
}
IInventory inv = (IInventory)te;
for (int l = 0; l < inv.getSize(); l++)
{
ItemStack itemstack = inv.getItem(l);
if (itemstack == null)
{
continue;
}
float f = world.random.nextFloat() * 0.8F + 0.1F;
float f1 = world.random.nextFloat() * 0.8F + 0.1F;
float f2 = world.random.nextFloat() * 0.8F + 0.1F;
while (itemstack.count > 0)
{
int i1 = world.random.nextInt(21) + 10;
if (i1 > itemstack.count)
{
i1 = itemstack.count ;
}
itemstack.count -= i1;
EntityItem entityitem = new EntityItem(world, (float)te.x + f, (float)te.y + f1, (float)te.z + f2, new ItemStack(itemstack.id, i1, itemstack.getData()));
float f3 = 0.05F;
entityitem.motX = (float)world.random.nextGaussian() * f3;
entityitem.motY = (float)world.random.nextGaussian() * f3 + 0.2F;
entityitem.motZ = (float)world.random.nextGaussian() * f3;
if (itemstack.hasTag())
{
entityitem.itemStack.setTag((NBTTagCompound)itemstack.getTag().clone());
}
world.addEntity(entityitem);
}
}
}
/**
* Get a list of all BaseMod loaded into the system
* {@link ModLoaderModContainer#findAll}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @return
*/
public static List<BaseMod> getLoadedMods()
{
return ModLoaderModContainer.findAll(BaseMod.class);
2012-04-15 03:01:03 +00:00
}
/**
2012-06-01 04:27:46 +00:00
* Get a logger instance {@link FMLCommonHandler#getFMLLogger()}
*
2012-04-15 03:01:03 +00:00
* @return
*/
public static Logger getLogger()
{
return FMLCommonHandler.instance().getFMLLogger();
}
2012-06-01 04:27:46 +00:00
public static Object getMinecraftInstance()
{
return getMinecraftServerInstance();
}
/**
* Get the minecraft server instance
* {@link FMLServerHandler#getServer()}
* @return
*/
public static MinecraftServer getMinecraftServerInstance()
{
return FMLBukkitHandler.instance().getServer();
}
2012-04-15 03:01:03 +00:00
/**
* Get a value from a field using reflection
* {@link ReflectionHelper#getPrivateValue(Class, Object, int)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param instanceclass
* @param instance
* @param fieldindex
* @return
*/
public static <T, E> T getPrivateValue(Class <? super E > instanceclass, E instance, int fieldindex)
{
return ReflectionHelper.getPrivateValue(instanceclass, instance, fieldindex);
}
/**
* Get a value from a field using reflection
* {@link ReflectionHelper#getPrivateValue(Class, Object, String)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param instanceclass
* @param instance
* @param field
* @return
*/
public static <T, E> T getPrivateValue(Class <? super E > instanceclass, E instance, String field)
{
return ReflectionHelper.getPrivateValue(instanceclass, instance, field);
}
2012-06-01 04:27:46 +00:00
/**
* Stubbed method on the server to return a unique model id
*
*/
public static int getUniqueBlockModelID(BaseMod mod, boolean inventoryRenderer)
{
return -1;
}
2012-04-15 03:01:03 +00:00
/**
* Get a new unique entity id
* {@link Entity#getNextId()}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @return
*/
public static int getUniqueEntityId()
{
2012-06-01 04:27:46 +00:00
return FMLCommonHandler.instance().nextUniqueEntityListId();
}
public static int getUniqueSpriteIndex(String path)
{
return -1;
}
/**
* To properly implement packet 250 protocol you should always check your
* channel is active prior to sending the packet
*
* @param player
* @param channel
* @return
*/
public static boolean isChannelActive(EntityPlayer player, String channel)
{
return FMLCommonHandler.instance().isChannelActive(channel, player);
}
public static boolean isGUIOpen(Class<?> gui)
{
return false;
2012-04-15 03:01:03 +00:00
}
/**
* Is the named mod loaded?
* {@link Loader#isModLoaded(String)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param modname
* @return
*/
public static boolean isModLoaded(String modname)
{
return Loader.isModLoaded(modname);
}
2012-06-01 04:27:46 +00:00
/**
* Implemented elsewhere
*/
@Deprecated
public static void loadConfig()
{
}
public static Object loadImage(Object renderEngine, String path) throws Exception
{
return null;
}
/**
* Call in from elsewhere. Unimplemented here.
* @param player
* @param item
*/
@Deprecated
public static void onItemPickup(EntityPlayer player, ItemStack item)
{
}
/**
* Call in from elsewhere. Unimplemented here.
*/
@Deprecated
public static void onTick(float tick, Object game)
{
}
public static void openGUI(EntityPlayer player, Object gui)
{
// NOOP
}
@Deprecated
public static void populateChunk(IChunkProvider generator, int chunkX, int chunkZ, World world)
{
}
2012-04-15 03:01:03 +00:00
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLBukkitHandler#handlePacket250(Packet250CustomPayload, EntityHuman)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param packet
*/
@Deprecated
public static void receivePacket(Packet250CustomPayload packet)
{
}
2012-06-01 04:27:46 +00:00
@Deprecated
public static Object[] registerAllKeys(Object[] keys)
{
return keys;
}
@Deprecated
public static void registerAllTextureOverrides(Object cache)
{
}
2012-04-15 03:01:03 +00:00
/**
* Register a new block
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param block
*/
public static void registerBlock(Block block)
{
FMLRegistry.registerBlock(block);
2012-04-15 03:01:03 +00:00
}
/**
* Register a new block
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param block
* @param itemclass
*/
public static void registerBlock(Block block, Class <? extends ItemBlock > itemclass)
{
FMLRegistry.registerBlock(block, itemclass);
2012-04-15 03:01:03 +00:00
}
/**
* Register a new entity ID
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityClass
* @param entityName
* @param id
*/
public static void registerEntityID(Class <? extends Entity > entityClass, String entityName, int id)
{
FMLRegistry.registerEntityID(entityClass, entityName, id);
2012-04-15 03:01:03 +00:00
}
/**
* Register a new entity ID
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityClass
* @param entityName
* @param id
* @param background
* @param foreground
*/
public static void registerEntityID(Class <? extends Entity > entityClass, String entityName, int id, int background, int foreground)
{
FMLRegistry.registerEntityID(entityClass, entityName, id, background, foreground);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
public static void registerKey(BaseMod mod, Object keyHandler, boolean allowRepeat)
{
// NOOP
}
2012-04-15 03:01:03 +00:00
/**
2012-06-01 04:27:46 +00:00
* Register the mod for packets on this channel. This only registers the
* channel with Forge Mod Loader, not with clients connecting- use
* BaseMod.onClientLogin to tell them about your custom channel
2012-04-15 03:01:03 +00:00
* {@link FMLCommonHandler#registerChannel(cpw.mods.fml.common.ModContainer, String)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param mod
* @param channel
*/
public static void registerPacketChannel(BaseMod mod, String channel)
{
FMLCommonHandler.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod), channel);
}
/**
* Register a new tile entity class
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param tileEntityClass
* @param id
*/
public static void registerTileEntity(Class <? extends TileEntity > tileEntityClass, String id)
{
FMLRegistry.registerTileEntity(tileEntityClass, id);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String id, Object renderer)
{
FMLRegistry.instance().registerTileEntity(tileEntityClass, id);
}
2012-04-15 03:01:03 +00:00
/**
2012-06-01 04:27:46 +00:00
* Remove a biome from the list of generated biomes
*
2012-04-15 03:01:03 +00:00
* @param biome
*/
public static void removeBiome(BiomeBase biome)
{
FMLRegistry.removeBiome(biome);
2012-04-15 03:01:03 +00:00
}
/**
* Remove a spawn
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityClass
* @param spawnList
*/
public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType spawnList)
{
FMLRegistry.removeSpawn(entityClass, spawnList, FMLBukkitHandler.instance().getDefaultOverworldBiomes());
2012-04-15 03:01:03 +00:00
}
/**
* Remove a spawn
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityClass
* @param spawnList
* @param biomes
*/
public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType spawnList, BiomeBase... biomes)
{
FMLRegistry.removeSpawn(entityClass, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
/**
* Remove a spawn
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityName
* @param spawnList
*/
public static void removeSpawn(String entityName, EnumCreatureType spawnList)
{
FMLRegistry.removeSpawn(entityName, spawnList, FMLBukkitHandler.instance().getDefaultOverworldBiomes());
2012-04-15 03:01:03 +00:00
}
/**
* Remove a spawn
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param entityName
* @param spawnList
* @param biomes
*/
public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeBase... biomes)
{
FMLRegistry.removeSpawn(entityName, spawnList, biomes);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
@Deprecated
public static boolean renderBlockIsItemFull3D(int modelID)
{
return false;
}
@Deprecated
public static void renderInvBlock(Object renderer, Block block, int metadata, int modelID)
{
// NOOP
}
@Deprecated
public static boolean renderWorldBlock(Object renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID)
{
return false;
}
2012-04-15 03:01:03 +00:00
/**
* Configuration is handled elsewhere
* {@link ModLoaderModContainer}
*/
@Deprecated
public static void saveConfig()
{
}
/**
2012-06-01 04:27:46 +00:00
* Send a chat message to the server
* {@link FMLServerHandler#handleChatPacket(Packet3Chat, EntityPlayer)}
*
2012-04-15 03:01:03 +00:00
* @param text
*/
@Deprecated
public static void serverChat(String text)
{
2012-06-01 04:27:46 +00:00
//TODO
}
@Deprecated
public static void serverLogin(Object handler, Packet1Login loginPacket)
{
//TODO
2012-04-15 03:01:03 +00:00
}
/**
* Indicate that you want to receive ticks
*
2012-06-01 04:27:46 +00:00
* @param mod receiving the events
* @param enable indicates whether you want to recieve them or not
* @param useClock Not used in server side: all ticks are sent on the server side (no render subticks)
2012-04-15 03:01:03 +00:00
*/
public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock)
{
ModLoaderHelper.updateStandardTicks(mod, enable, useClock);
2012-04-15 03:01:03 +00:00
}
2012-06-01 04:27:46 +00:00
public static void setInGUIHook(BaseMod mod, boolean enable, boolean useClock)
{
ModLoaderHelper.updateGUITicks(mod, enable, useClock);
}
2012-04-15 03:01:03 +00:00
/**
* Set a private field to a value using reflection
* {@link ReflectionHelper#setPrivateValue(Class, Object, int, Object)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param instanceclass
* @param instance
* @param fieldindex
* @param value
*/
public static <T, E> void setPrivateValue(Class <? super T > instanceclass, T instance, int fieldindex, E value)
{
ReflectionHelper.setPrivateValue(instanceclass, instance, fieldindex, value);
}
/**
* Set a private field to a value using reflection
* {@link ReflectionHelper#setPrivateValue(Class, Object, String, Object)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param instanceclass
* @param instance
* @param field
* @param value
*/
public static <T, E> void setPrivateValue(Class <? super T > instanceclass, T instance, String field, E value)
{
ReflectionHelper.setPrivateValue(instanceclass, instance, field, value);
}
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLBukkitHandler#onItemCrafted(EntityHuman, ItemStack, IInventory)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param player
* @param item
* @param matrix
*/
@Deprecated
public static void takenFromCrafting(EntityHuman player, ItemStack item, IInventory matrix)
2012-04-15 03:01:03 +00:00
{
}
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* {@link FMLBukkitHandler#onItemSmelted(EntityHuman, ItemStack)}
2012-06-01 04:27:46 +00:00
*
2012-04-15 03:01:03 +00:00
* @param player
* @param item
*/
@Deprecated
public static void takenFromFurnace(EntityHuman player, ItemStack item)
2012-04-15 03:01:03 +00:00
{
}
/**
* Throw the offered exception. Likely will stop the game.
* {@link FMLBukkitHandler#raiseException(Throwable, String, boolean)}
* @param message
* @param e
*/
public static void throwException(String message, Throwable e)
{
FMLBukkitHandler.instance().raiseException(e, message, true);
}
/**
* To properly implement packet 250 protocol you should always check your channel
* is active prior to sending the packet
*
* @param player
* @param channel
* @return
*/
public static boolean isChannelActive(EntityHuman player, String channel)
2012-04-15 03:01:03 +00:00
{
return FMLCommonHandler.instance().isChannelActive(channel, player);
}
}