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

519 lines
14 KiB
Java
Raw Normal View History

2012-03-30 14:11:13 +00:00
/*
2012-04-01 06:14:14 +00:00
* The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
2012-03-30 14:11:13 +00:00
*
* 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
*/
2012-03-30 05:12:59 +00:00
package net.minecraft.src;
2012-03-28 16:53:08 +00:00
import java.util.List;
import java.util.logging.Logger;
2012-04-03 21:04:26 +00:00
import net.minecraft.server.MinecraftServer;
import cpw.mods.fml.common.FMLHooks;
import cpw.mods.fml.common.Loader;
2012-04-03 03:06:30 +00:00
import cpw.mods.fml.common.ReflectionHelper;
import cpw.mods.fml.server.FMLHandler;
import cpw.mods.fml.server.ModLoaderModContainer;
2012-03-28 16:53:08 +00:00
public class ModLoader {
2012-04-03 03:06:30 +00:00
/**
*
* @param achievement
* @param name
* @param description
*/
2012-04-01 06:14:14 +00:00
public static void addAchievementDesc(Achievement achievement, String name, String description) {
2012-04-03 03:06:30 +00:00
// NOOP on the server??
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* @param id
* @param metadata
* @return
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static int addAllFuel(int id, int metadata) {
2012-03-28 17:29:23 +00:00
return 0;
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method has been unimplemented in server implementations for some time.
*
* @param armor
* @return
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static int addArmor(String armor) {
2012-03-28 17:29:23 +00:00
return 0;
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method does not work. Creation of a BiomeGenBase is sufficient to populate this array
*
* @param biome
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addBiome(BiomeGenBase biome) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not generate names
* @param key
* @param value
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addLocalization(String key, String value) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not generate names
* @param key
* @param lang
* @param value
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addLocalization(String key, String lang, String value) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not generate names
* @param instance
* @param name
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addName(Object instance, String name) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not generate names
* @param instance
* @param lang
* @param name
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addName(Object instance, String lang, String name) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not render textures
* @param fileToOverride
* @param fileToAdd
* @return
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static int addOverride(String fileToOverride, String fileToAdd) {
2012-03-28 17:29:23 +00:00
return 0;
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Unimplemented on the server as it does not render textures
* @param path
* @param overlayPath
* @param index
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void addOverride(String path, String overlayPath, int index) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a Shaped Recipe
* @param output
* @param params
*/
2012-04-01 06:14:14 +00:00
public static void addRecipe(ItemStack output, Object... params) {
CommonRegistry.addRecipe(output, params);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a shapeless recipe
* @param output
* @param params
*/
2012-04-01 06:14:14 +00:00
public static void addShapelessRecipe(ItemStack output, Object... params) {
CommonRegistry.addShapelessRecipe(output, params);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a new product to be smelted
* @param input
* @param output
*/
2012-04-01 06:14:14 +00:00
public static void addSmelting(int input, ItemStack output) {
CommonRegistry.addSmelting(input, output);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a mob to the spawn list
* @param entityClass
* @param weightedProb
* @param min
* @param max
* @param spawnList
*/
2012-04-01 06:14:14 +00:00
public static void addSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList) {
2012-04-03 03:06:30 +00:00
CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a mob to the spawn list
* @param entityClass
* @param weightedProb
* @param min
* @param max
* @param spawnList
* @param biomes
*/
2012-04-01 06:14:14 +00:00
public static void addSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) {
2012-03-31 02:26:16 +00:00
CommonRegistry.addSpawn(entityClass, weightedProb, min, max, spawnList, biomes);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a mob to the spawn list
* @param entityName
* @param weightedProb
* @param min
* @param max
* @param spawnList
*/
2012-04-01 06:14:14 +00:00
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList) {
2012-04-03 03:06:30 +00:00
CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Add a mob to the spawn list
* @param entityName
* @param weightedProb
* @param min
* @param max
* @param spawnList
* @param biomes
*/
2012-04-01 06:14:14 +00:00
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) {
2012-03-31 02:26:16 +00:00
CommonRegistry.addSpawn(entityName, weightedProb, min, max, spawnList, biomes);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* @param world
* @param x
* @param y
* @param z
* @param xVel
* @param zVel
* @param item
* @return
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) {
2012-03-28 17:29:23 +00:00
return false;
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
2012-04-03 21:04:26 +00:00
* Remove a container and drop all the items in it on the ground around
2012-04-03 03:06:30 +00:00
* @param world
* @param x
* @param y
* @param z
*/
2012-04-01 06:14:14 +00:00
public static void genericContainerRemoval(World world, int x, int y, int z) {
2012-04-03 20:12:19 +00:00
TileEntity te=world.func_451_k(x, y, z);
if (!(te instanceof IInventory)) {
return;
}
IInventory inv=(IInventory)te;
for (int l = 0; l < inv.func_83_a(); l++)
{
ItemStack itemstack = inv.func_82_a(l);
if (itemstack == null)
{
continue;
}
float f = world.field_803_m.nextFloat() * 0.8F + 0.1F;
float f1 = world.field_803_m.nextFloat() * 0.8F + 0.1F;
float f2 = world.field_803_m.nextFloat() * 0.8F + 0.1F;
while (itemstack.field_853_a > 0)
{
int i1 = world.field_803_m.nextInt(21) + 10;
if (i1 > itemstack.field_853_a)
{
i1 = itemstack.field_853_a ;
}
itemstack.field_853_a -= i1;
EntityItem entityitem = new EntityItem(world, (float)te.field_478_b + f, (float)te.field_483_c + f1, (float)te.field_482_d + f2, new ItemStack(itemstack.field_855_c, i1, itemstack.func_21125_h()));
float f3 = 0.05F;
entityitem.field_319_o = (float)world.field_803_m.nextGaussian() * f3;
entityitem.field_318_p = (float)world.field_803_m.nextGaussian() * f3 + 0.2F;
entityitem.field_317_q = (float)world.field_803_m.nextGaussian() * f3;
if (itemstack.func_40608_n())
{
entityitem.field_429_a.func_40604_d((NBTTagCompound)itemstack.func_40607_o().func_40468_b());
}
world.func_526_a(entityitem);
}
}
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Get a list of all BaseMod loaded into the system
* @return
*/
2012-04-01 06:14:14 +00:00
public static List<BaseMod> getLoadedMods() {
2012-03-31 02:26:16 +00:00
return ModLoaderModContainer.findAll();
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Get a logger instance
* @return
*/
public static Logger getLogger() {
return FMLHandler.getFMLLogger();
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Get a value from a field using reflection
* @param instanceclass
* @param instance
* @param fieldindex
* @return
*/
2012-04-01 06:14:14 +00:00
public static <T, E> T getPrivateValue(Class<? super E> instanceclass, E instance, int fieldindex) {
return ReflectionHelper.getPrivateValue(instanceclass, instance, fieldindex);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Get a value from a field using reflection
* @param instanceclass
* @param instance
* @param field
* @return
*/
2012-04-01 06:14:14 +00:00
public static <T, E> T getPrivateValue(Class<? super E> instanceclass, E instance, String field) {
return ReflectionHelper.getPrivateValue(instanceclass, instance, field);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Get a new unique entity id
* @return
*/
2012-04-01 06:14:14 +00:00
public static int getUniqueEntityId() {
2012-04-03 03:06:30 +00:00
return Entity.getNextId();
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Is the named mod loaded?
* @param modname
* @return
*/
2012-04-01 06:14:14 +00:00
public static boolean isModLoaded(String modname) {
2012-03-31 02:26:16 +00:00
return Loader.isModLoaded(modname);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
2012-04-03 21:04:26 +00:00
* This method is a call in hook from modified external code. Implemented elsewhere.
2012-04-03 03:06:30 +00:00
* @param packet
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void receivePacket(Packet250CustomPayload packet) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Register a new block
* @param block
*/
2012-04-01 06:14:14 +00:00
public static void registerBlock(Block block) {
2012-03-30 05:12:59 +00:00
CommonRegistry.registerBlock(block);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Register a new block
* @param block
* @param itemclass
*/
2012-04-01 06:14:14 +00:00
public static void registerBlock(Block block, Class<? extends ItemBlock> itemclass) {
2012-03-30 05:12:59 +00:00
CommonRegistry.registerBlock(block, itemclass);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Register a new entity ID
* @param entityClass
* @param entityName
* @param id
*/
2012-04-01 06:14:14 +00:00
public static void registerEntityID(Class<? extends Entity> entityClass, String entityName, int id) {
2012-03-30 05:12:59 +00:00
CommonRegistry.registerEntityID(entityClass, entityName, id);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Register a new entity ID
* @param entityClass
* @param entityName
* @param id
* @param background
* @param foreground
*/
2012-04-01 06:14:14 +00:00
public static void registerEntityID(Class<? extends Entity> entityClass, String entityName, int id, int background, int foreground) {
2012-03-30 05:12:59 +00:00
CommonRegistry.registerEntityID(entityClass, entityName, id, background, foreground);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
2012-04-03 21:04:26 +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-03 03:06:30 +00:00
* @param mod
* @param channel
*/
2012-04-01 06:14:14 +00:00
public static void registerPacketChannel(BaseMod mod, String channel) {
2012-04-03 21:04:26 +00:00
FMLHooks.instance().registerChannel(ModLoaderModContainer.findContainerFor(mod),channel);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Register a new tile entity class
* @param tileEntityClass
* @param id
*/
2012-04-01 06:14:14 +00:00
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String id) {
2012-03-30 05:12:59 +00:00
CommonRegistry.registerTileEntity(tileEntityClass, id);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Remove a biome. This code will probably not work correctly.
* @param biome
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void removeBiome(BiomeGenBase biome) {
2012-03-30 05:12:59 +00:00
CommonRegistry.removeBiome(biome);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Remove a spawn
* @param entityClass
* @param spawnList
*/
2012-04-01 06:14:14 +00:00
public static void removeSpawn(Class<? extends EntityLiving> entityClass, EnumCreatureType spawnList) {
2012-04-03 03:06:30 +00:00
CommonRegistry.removeSpawn(entityClass, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Remove a spawn
* @param entityClass
* @param spawnList
* @param biomes
*/
2012-04-01 06:14:14 +00:00
public static void removeSpawn(Class<? extends EntityLiving> entityClass, EnumCreatureType spawnList, BiomeGenBase... biomes) {
2012-03-30 05:12:59 +00:00
CommonRegistry.removeSpawn(entityClass, spawnList, biomes);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Remove a spawn
* @param entityName
* @param spawnList
*/
2012-04-01 06:14:14 +00:00
public static void removeSpawn(String entityName, EnumCreatureType spawnList) {
2012-04-03 03:06:30 +00:00
CommonRegistry.removeSpawn(entityName, spawnList, FMLHandler.instance().getDefaultOverworldBiomes());
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Remove a spawn
* @param entityName
* @param spawnList
* @param biomes
*/
2012-04-01 06:14:14 +00:00
public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) {
2012-03-30 05:12:59 +00:00
CommonRegistry.removeSpawn(entityName, spawnList, biomes);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
2012-04-03 20:12:19 +00:00
* Configuration is handled elsewhere
2012-04-03 03:06:30 +00:00
*/
2012-04-03 20:12:19 +00:00
@Deprecated
2012-04-01 06:14:14 +00:00
public static void saveConfig() {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method is unimplemented on the server: it is meant for clients to send chat to the server
* @param text
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void serverChat(String text) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
/**
* Indicate that you want to receive ticks
*
2012-04-01 06:14:14 +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-01 06:14:14 +00:00
public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock) {
ModLoaderModContainer mlmc = (ModLoaderModContainer) ModLoaderModContainer.findContainerFor(mod);
2012-03-30 05:12:59 +00:00
mlmc.setTicking(enable);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Set a private field to a value using reflection
* @param instanceclass
* @param instance
* @param fieldindex
* @param value
*/
2012-04-01 06:14:14 +00:00
public static <T, E> void setPrivateValue(Class<? super T> instanceclass, T instance, int fieldindex, E value) {
ReflectionHelper.setPrivateValue(instanceclass, instance, fieldindex, value);
2012-03-28 17:29:23 +00:00
}
2012-04-03 03:06:30 +00:00
/**
* Set a private field to a value using reflection
* @param instanceclass
* @param instance
* @param field
* @param value
*/
2012-04-01 06:14:14 +00:00
public static <T, E> void setPrivateValue(Class<? super T> instanceclass, T instance, String field, E value) {
ReflectionHelper.setPrivateValue(instanceclass, instance, field, value);
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* @param player
* @param item
* @param matrix
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* This method is a call in hook from modified external code. Implemented elsewhere.
* @param player
* @param item
*/
@Deprecated
2012-04-01 06:14:14 +00:00
public static void takenFromFurnace(EntityPlayer player, ItemStack item) {
2012-03-28 17:29:23 +00:00
}
2012-03-28 16:53:08 +00:00
2012-04-03 03:06:30 +00:00
/**
* Throw the offered exception. Likely will stop the game.
* @param message
* @param e
*/
2012-04-01 06:14:14 +00:00
public static void throwException(String message, Throwable e) {
2012-04-03 03:06:30 +00:00
FMLHandler.instance().raiseException(e, message, true);
2012-03-28 17:29:23 +00:00
}
2012-04-03 03:06:30 +00:00
/**
* Get the minecraft server instance
* @return
*/
public static MinecraftServer getMinecraftServerInstance() {
2012-04-03 03:06:30 +00:00
return FMLHandler.instance().getServer();
}
2012-03-30 05:12:59 +00:00
}