Run Astyle over the FML code. Happy lex?

This commit is contained in:
Christian Weeks committed 2012-04-05 10:07:52 -04:00
1 parent 1e6eec768c
commit c06fc00f24
21 files changed
+2765 -2212

No files matched your search

+240 -178
View File
@@ -1,12 +1,12 @@
/*
* 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
*/
@@ -34,198 +34,260 @@ import cpw.mods.fml.common.FMLHooks;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
public class FMLHandler {
private static final FMLHandler INSTANCE=new FMLHandler();
private MinecraftServer server;
public class FMLHandler
{
private static final FMLHandler INSTANCE = new FMLHandler();
private BiomeGenBase[] defaultOverworldBiomes;
private MinecraftServer server;
public void onPreLoad(MinecraftServer minecraftServer) {
server = minecraftServer;
Loader.instance().loadMods();
}
private BiomeGenBase[] defaultOverworldBiomes;
public void onLoadComplete() {
Loader.instance().initializeMods();
}
public void onPreTick() {
FMLHooks.instance().gameTickStart();
}
public void onPostTick() {
FMLHooks.instance().gameTickEnd();
}
public MinecraftServer getServer() {
return server;
}
public static Logger getMinecraftLogger() {
return MinecraftServer.field_6038_a;
}
public void onChunkPopulate(IChunkProvider chunkProvider, int chunkX, int chunkZ, World world, IChunkProvider generator) {
Random fmlRandom = new Random(world.func_22079_j());
long xSeed = fmlRandom.nextLong() >> 2 + 1L;
long zSeed = fmlRandom.nextLong() >> 2 + 1L;
fmlRandom.setSeed((xSeed * chunkX + zSeed * chunkZ) ^ world.func_22079_j());
for (ModContainer mod : Loader.getModList()) {
if (mod.generatesWorld()) {
mod.getWorldGenerator().generate(fmlRandom, chunkX, chunkZ, world, generator, chunkProvider);
}
public void onPreLoad(MinecraftServer minecraftServer)
{
server = minecraftServer;
Loader.instance().loadMods();
}
}
public int fuelLookup(int itemId, int itemDamage) {
int fv = 0;
for (ModContainer mod : Loader.getModList()) {
fv = Math.max(fv, mod.lookupFuelValue(itemId, itemDamage));
public void onLoadComplete()
{
Loader.instance().initializeMods();
}
return fv;
}
public boolean isModLoaderMod(Class<?> clazz) {
return BaseMod.class.isAssignableFrom(clazz);
}
public ModContainer loadBaseModMod(Class<?> clazz, String canonicalPath) {
@SuppressWarnings("unchecked")
Class<? extends BaseMod> bmClazz = (Class<? extends BaseMod>) clazz;
return new ModLoaderModContainer(bmClazz, canonicalPath);
}
public void notifyItemPickup(EntityItem entityItem, EntityPlayer entityPlayer) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsPickupNotification()) {
mod.getPickupNotifier().notifyPickup(entityItem, entityPlayer);
}
public void onPreTick()
{
FMLHooks.instance().gameTickStart();
}
}
public static Logger getFMLLogger() {
return Loader.log;
}
public void raiseException(Throwable exception, String message, boolean stopGame) {
getFMLLogger().throwing("FMLHandler", "raiseException", exception);
throw new RuntimeException(exception);
}
/**
* @param p_21036_1_
* @param var13
* @param var15
* @param var17
* @param var9
* @param var10
* @param var12
* @return
*/
public boolean tryDispensingEntity(World world, double x, double y, double z, byte xVelocity, byte zVelocity, ItemStack item) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsToDispense() && mod.getDispenseHandler().dispense(x, y, z, xVelocity, zVelocity, world, item)) {
return true;
}
public void onPostTick()
{
FMLHooks.instance().gameTickEnd();
}
return false;
}
/**
* @return the instance
*/
public static FMLHandler instance() {
return INSTANCE;
}
public MinecraftServer getServer()
{
return server;
}
/**
* @return
*/
public BiomeGenBase[] getDefaultOverworldBiomes() {
if (defaultOverworldBiomes==null) {
ArrayList<BiomeGenBase> biomes=new ArrayList<BiomeGenBase>(20);
for (int i=0; i<23; i++) {
if ("Sky".equals(BiomeGenBase.field_35521_a[i].field_6163_m) || "Hell".equals(BiomeGenBase.field_35521_a[i].field_6163_m)) {
continue;
public static Logger getMinecraftLogger()
{
return MinecraftServer.field_6038_a;
}
public void onChunkPopulate(IChunkProvider chunkProvider, int chunkX, int chunkZ, World world, IChunkProvider generator)
{
Random fmlRandom = new Random(world.func_22079_j());
long xSeed = fmlRandom.nextLong() >> 2 + 1L;
long zSeed = fmlRandom.nextLong() >> 2 + 1L;
fmlRandom.setSeed((xSeed * chunkX + zSeed * chunkZ) ^ world.func_22079_j());
for (ModContainer mod : Loader.getModList())
{
if (mod.generatesWorld())
{
mod.getWorldGenerator().generate(fmlRandom, chunkX, chunkZ, world, generator, chunkProvider);
}
}
biomes.add(BiomeGenBase.field_35521_a[i]);
}
defaultOverworldBiomes=new BiomeGenBase[biomes.size()];
biomes.toArray(defaultOverworldBiomes);
}
return defaultOverworldBiomes;
}
public void onItemCrafted(EntityPlayer player, ItemStack craftedItem, IInventory craftingGrid) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsCraftingNotification()) {
mod.getCraftingHandler().onCrafting(player,craftedItem,craftingGrid);
}
}
}
public void onItemSmelted(EntityPlayer player, ItemStack smeltedItem) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsCraftingNotification()) {
mod.getCraftingHandler().onSmelting(player,smeltedItem);
}
}
}
public boolean handleChatPacket(Packet3Chat chat, EntityPlayer player) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsNetworkPackets() && mod.getNetworkHandler().onChat(chat,player)) {
return true;
}
}
return false;
}
public void handlePacket250(Packet250CustomPayload packet, EntityPlayer player) {
if ("REGISTER".equals(packet.field_44005_a) || "UNREGISTER".equals(packet.field_44005_a)) {
handleClientRegistration(packet, player);
return;
}
ModContainer mod = FMLHooks.instance().getModForChannel(packet.field_44005_a);
if (mod!=null) {
mod.getNetworkHandler().onPacket250Packet(packet, player);
}
}
public int fuelLookup(int itemId, int itemDamage)
{
int fv = 0;
/**
* @param packet
*/
private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player) {
try {
for (String channel : new String(packet.field_44004_c,"UTF8").split("\0")) {
// Skip it if we don't know it
if (FMLHooks.instance().getModForChannel(channel)==null) {
continue;
for (ModContainer mod : Loader.getModList())
{
fv = Math.max(fv, mod.lookupFuelValue(itemId, itemDamage));
}
if ("REGISTER".equals(packet.field_44005_a)) {
FMLHooks.instance().activateChannel(player,channel);
} else {
FMLHooks.instance().deactivateChannel(player,channel);
}
}
} catch (UnsupportedEncodingException e) {
getMinecraftLogger().warning("Received invalid registration packet");
}
}
public void handleLogin(Packet1Login loginPacket, NetworkManager networkManager) {
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsNetworkPackets()) {
mod.getNetworkHandler().onLogin(loginPacket, networkManager);
}
return fv;
}
public boolean isModLoaderMod(Class<?> clazz)
{
return BaseMod.class.isAssignableFrom(clazz);
}
public ModContainer loadBaseModMod(Class<?> clazz, String canonicalPath)
{
@SuppressWarnings("unchecked")
Class <? extends BaseMod > bmClazz = (Class <? extends BaseMod >) clazz;
return new ModLoaderModContainer(bmClazz, canonicalPath);
}
public void notifyItemPickup(EntityItem entityItem, EntityPlayer entityPlayer)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsPickupNotification())
{
mod.getPickupNotifier().notifyPickup(entityItem, entityPlayer);
}
}
}
public static Logger getFMLLogger()
{
return Loader.log;
}
public void raiseException(Throwable exception, String message, boolean stopGame)
{
getFMLLogger().throwing("FMLHandler", "raiseException", exception);
throw new RuntimeException(exception);
}
/**
* @param p_21036_1_
* @param var13
* @param var15
* @param var17
* @param var9
* @param var10
* @param var12
* @return
*/
public boolean tryDispensingEntity(World world, double x, double y, double z, byte xVelocity, byte zVelocity, ItemStack item)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsToDispense() && mod.getDispenseHandler().dispense(x, y, z, xVelocity, zVelocity, world, item))
{
return true;
}
}
return false;
}
/**
* @return the instance
*/
public static FMLHandler instance()
{
return INSTANCE;
}
/**
* @return
*/
public BiomeGenBase[] getDefaultOverworldBiomes()
{
if (defaultOverworldBiomes == null)
{
ArrayList<BiomeGenBase> biomes = new ArrayList<BiomeGenBase>(20);
for (int i = 0; i < 23; i++)
{
if ("Sky".equals(BiomeGenBase.field_35521_a[i].field_6163_m) || "Hell".equals(BiomeGenBase.field_35521_a[i].field_6163_m))
{
continue;
}
biomes.add(BiomeGenBase.field_35521_a[i]);
}
defaultOverworldBiomes = new BiomeGenBase[biomes.size()];
biomes.toArray(defaultOverworldBiomes);
}
return defaultOverworldBiomes;
}
public void onItemCrafted(EntityPlayer player, ItemStack craftedItem, IInventory craftingGrid)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsCraftingNotification())
{
mod.getCraftingHandler().onCrafting(player, craftedItem, craftingGrid);
}
}
}
public void onItemSmelted(EntityPlayer player, ItemStack smeltedItem)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsCraftingNotification())
{
mod.getCraftingHandler().onSmelting(player, smeltedItem);
}
}
}
public boolean handleChatPacket(Packet3Chat chat, EntityPlayer player)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsNetworkPackets() && mod.getNetworkHandler().onChat(chat, player))
{
return true;
}
}
return false;
}
public void handlePacket250(Packet250CustomPayload packet, EntityPlayer player)
{
if ("REGISTER".equals(packet.field_44005_a) || "UNREGISTER".equals(packet.field_44005_a))
{
handleClientRegistration(packet, player);
return;
}
ModContainer mod = FMLHooks.instance().getModForChannel(packet.field_44005_a);
if (mod != null)
{
mod.getNetworkHandler().onPacket250Packet(packet, player);
}
}
/**
* @param packet
*/
private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player)
{
try
{
for (String channel : new String(packet.field_44004_c, "UTF8").split("\0"))
{
// Skip it if we don't know it
if (FMLHooks.instance().getModForChannel(channel) == null)
{
continue;
}
if ("REGISTER".equals(packet.field_44005_a))
{
FMLHooks.instance().activateChannel(player, channel);
}
else
{
FMLHooks.instance().deactivateChannel(player, channel);
}
}
}
catch (UnsupportedEncodingException e)
{
getMinecraftLogger().warning("Received invalid registration packet");
}
}
public void handleLogin(Packet1Login loginPacket, NetworkManager networkManager)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsNetworkPackets())
{
mod.getNetworkHandler().onLogin(loginPacket, networkManager);
}
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.field_44005_a = "REGISTER";
packet.field_44004_c = FMLHooks.instance().getPacketRegistry();
packet.field_44003_b = packet.field_44004_c.length;
networkManager.func_745_a(packet);
}
Packet250CustomPayload packet=new Packet250CustomPayload();
packet.field_44005_a="REGISTER";
packet.field_44004_c=FMLHooks.instance().getPacketRegistry();
packet.field_44003_b=packet.field_44004_c.length;
networkManager.func_745_a(packet);
}
}
@@ -1,13 +1,13 @@
/*
* 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
*/
@@ -36,343 +36,468 @@ import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderException;
import cpw.mods.fml.common.ModContainer;
public class ModLoaderModContainer implements ModContainer {
private Class<? extends BaseMod> modClazz;
private BaseMod mod;
private boolean isTicking;
private String modSource ;
private ArrayList<String> dependencies;
private ArrayList<String> preDependencies;
private ArrayList<String> postDependencies;
public ModLoaderModContainer(Class<? extends BaseMod> modClazz, String modSource) {
this.modClazz=modClazz;
this.modSource =modSource;
}
public boolean wantsPreInit() {
return true;
}
public boolean wantsPostInit() {
return true;
}
@Override
public void preInit() {
try {
configureMod();
mod=modClazz.newInstance();
} catch (Exception e) {
throw new LoaderException(e);
public class ModLoaderModContainer implements ModContainer
{
private Class <? extends BaseMod > modClazz;
private BaseMod mod;
private boolean isTicking;
private String modSource ;
private ArrayList<String> dependencies;
private ArrayList<String> preDependencies;
private ArrayList<String> postDependencies;
public ModLoaderModContainer(Class <? extends BaseMod > modClazz, String modSource)
{
this.modClazz = modClazz;
this.modSource = modSource;
}
}
/**
*
*/
private void configureMod() {
File configDir=Loader.instance().getConfigDir();
File modConfig=new File(configDir,String.format("%s.cfg", modClazz.getSimpleName()));
Properties props=new Properties();
if (modConfig.exists()) {
try {
FileReader configReader = new FileReader(modConfig);
props.load(configReader);
configReader.close();
} catch (Exception e) {
Loader.log.severe(String.format("Error occured reading mod configuration file %s",modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
}
public boolean wantsPreInit()
{
return true;
}
StringBuffer comments = new StringBuffer();
comments.append("MLProperties: name (type:default) min:max -- information\n");
try {
for (Field f : modClazz.getDeclaredFields()) {
if (!Modifier.isStatic(f.getModifiers())) {
continue;
public boolean wantsPostInit()
{
return true;
}
@Override
public void preInit()
{
try
{
configureMod();
mod = modClazz.newInstance();
}
catch (Exception e)
{
throw new LoaderException(e);
}
}
/**
*
*/
private void configureMod()
{
File configDir = Loader.instance().getConfigDir();
File modConfig = new File(configDir, String.format("%s.cfg", modClazz.getSimpleName()));
Properties props = new Properties();
if (modConfig.exists())
{
try
{
FileReader configReader = new FileReader(modConfig);
props.load(configReader);
configReader.close();
}
catch (Exception e)
{
Loader.log.severe(String.format("Error occured reading mod configuration file %s", modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
}
}
if (!f.isAnnotationPresent(MLProp.class)) {
continue;
}
StringBuffer comments = new StringBuffer();
comments.append("MLProperties: name (type:default) min:max -- information\n");
MLProp property = f.getAnnotation(MLProp.class);
String propertyName = property.name().length() > 0 ? property.name() : f.getName();
String propertyValue = null;
Object defaultValue = null;
try {
defaultValue = f.get(null);
propertyValue = props.getProperty(propertyName, extractValue(defaultValue));
Object currentValue = parseValue(propertyValue, property, f.getType());
if (currentValue != null && !currentValue.equals(defaultValue)) {
f.set(null, currentValue);
}
} catch (Exception e) {
Loader.log.severe(String.format("Invalid configuration found for %s in %s", propertyName, modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
} finally {
comments.append(String.format("MLProp : %s (%s:%s", propertyName, f.getType().getName(), defaultValue));
if (property.min() != Double.MIN_VALUE) {
comments.append(",>=").append(String.format("%.1f", property.min()));
}
if (property.max() != Double.MAX_VALUE) {
comments.append(",<=").append(String.format("%.1f", property.max()));
}
comments.append(")");
if (property.info().length() > 0) {
comments.append(" -- ").append(property.info());
}
if (propertyValue != null) {
props.setProperty(propertyName, extractValue(propertyValue));
}
try
{
for (Field f : modClazz.getDeclaredFields())
{
if (!Modifier.isStatic(f.getModifiers()))
{
continue;
}
if (!f.isAnnotationPresent(MLProp.class))
{
continue;
}
MLProp property = f.getAnnotation(MLProp.class);
String propertyName = property.name().length() > 0 ? property.name() : f.getName();
String propertyValue = null;
Object defaultValue = null;
try
{
defaultValue = f.get(null);
propertyValue = props.getProperty(propertyName, extractValue(defaultValue));
Object currentValue = parseValue(propertyValue, property, f.getType());
if (currentValue != null && !currentValue.equals(defaultValue))
{
f.set(null, currentValue);
}
}
catch (Exception e)
{
Loader.log.severe(String.format("Invalid configuration found for %s in %s", propertyName, modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
}
finally
{
comments.append(String.format("MLProp : %s (%s:%s", propertyName, f.getType().getName(), defaultValue));
if (property.min() != Double.MIN_VALUE)
{
comments.append(",>=").append(String.format("%.1f", property.min()));
}
if (property.max() != Double.MAX_VALUE)
{
comments.append(",<=").append(String.format("%.1f", property.max()));
}
comments.append(")");
if (property.info().length() > 0)
{
comments.append(" -- ").append(property.info());
}
if (propertyValue != null)
{
props.setProperty(propertyName, extractValue(propertyValue));
}
}
}
}
finally
{
try
{
FileWriter configWriter = new FileWriter(modConfig);
props.store(configWriter, comments.toString());
configWriter.close();
}
catch (IOException e)
{
Loader.log.warning(String.format("Error trying to write the config file %s", modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
}
}
}
} finally {
try {
FileWriter configWriter=new FileWriter(modConfig);
props.store(configWriter, comments.toString());
configWriter.close();
} catch (IOException e) {
Loader.log.warning(String.format("Error trying to write the config file %s",modConfig.getName()));
Loader.log.throwing("ModLoaderModContainer", "configureMod", e);
throw new LoaderException(e);
}
}
}
private Object parseValue(String val, MLProp property, Class<?> type) {
if (type.isAssignableFrom(String.class)) {
return (String)val;
} else if (type.isAssignableFrom(Boolean.TYPE)) {
return Boolean.parseBoolean(val);
} else if (Number.class.isAssignableFrom(type)) {
Number n=null;
if (type.isAssignableFrom(Double.TYPE)) {
n=Double.parseDouble(val);
} else if (type.isAssignableFrom(Float.TYPE)) {
n=Float.parseFloat(val);
} else if (type.isAssignableFrom(Long.TYPE)) {
n=Long.parseLong(val);
} else if (type.isAssignableFrom(Integer.TYPE)) {
n=Integer.parseInt(val);
} else if (type.isAssignableFrom(Short.TYPE)) {
n=Short.parseShort(val);
} else if (type.isAssignableFrom(Byte.TYPE)) {
n=Byte.parseByte(val);
} else {
throw new IllegalArgumentException("MLProp declared on non-standard type");
}
if (n.doubleValue()<property.min() || n.doubleValue()>property.max()) {
private Object parseValue(String val, MLProp property, Class<?> type)
{
if (type.isAssignableFrom(String.class))
{
return (String)val;
}
else if (type.isAssignableFrom(Boolean.TYPE))
{
return Boolean.parseBoolean(val);
}
else if (Number.class.isAssignableFrom(type))
{
Number n = null;
if (type.isAssignableFrom(Double.TYPE))
{
n = Double.parseDouble(val);
}
else if (type.isAssignableFrom(Float.TYPE))
{
n = Float.parseFloat(val);
}
else if (type.isAssignableFrom(Long.TYPE))
{
n = Long.parseLong(val);
}
else if (type.isAssignableFrom(Integer.TYPE))
{
n = Integer.parseInt(val);
}
else if (type.isAssignableFrom(Short.TYPE))
{
n = Short.parseShort(val);
}
else if (type.isAssignableFrom(Byte.TYPE))
{
n = Byte.parseByte(val);
}
else
{
throw new IllegalArgumentException("MLProp declared on non-standard type");
}
if (n.doubleValue() < property.min() || n.doubleValue() > property.max())
{
return null;
}
else
{
return n;
}
}
return null;
} else {
return n;
}
}
return null;
}
private String extractValue(Object value) {
if (String.class.isInstance(value)) {
return (String)value;
} else if (Number.class.isInstance(value)) {
return String.valueOf(value);
} else {
throw new IllegalArgumentException("MLProp declared on non-standard type");
private String extractValue(Object value)
{
if (String.class.isInstance(value))
{
return (String)value;
}
else if (Number.class.isInstance(value))
{
return String.valueOf(value);
}
else
{
throw new IllegalArgumentException("MLProp declared on non-standard type");
}
}
}
@Override
public void init() {
mod.load();
}
@Override
public void postInit() {
mod.modsLoaded();
}
@Override
public void tickStart() {
if (isTicking) {
isTicking=mod.onTickInGame(FMLHandler.instance().getServer());
@Override
public void init()
{
mod.load();
}
}
@Override
public void tickEnd() {
// NOOP for modloader
}
@Override
public String getName() {
return mod!=null?mod.getName():null;
}
public static ModContainer findContainerFor(BaseMod mod) {
for (ModContainer mc :Loader.getModList()) {
if (mc.matches(mod)) {
return mc;
}
@Override
public void postInit()
{
mod.modsLoaded();
}
return null;
}
@Override
public boolean matches(Object mod) {
return modClazz.isInstance(mod);
}
public void setTicking(boolean enable) {
isTicking=enable;
}
public static List<BaseMod> findAll() {
ArrayList<BaseMod> modList=new ArrayList<BaseMod>();
for (ModContainer mc : Loader.getModList()) {
if (mc instanceof ModLoaderModContainer) {
modList.add(((ModLoaderModContainer)mc).mod);
}
@Override
public void tickStart()
{
if (isTicking)
{
isTicking = mod.onTickInGame(FMLHandler.instance().getServer());
}
}
return modList;
}
@Override
public String getSource() {
return modSource;
}
@Override
public Object getMod() {
return mod;
}
@Override
public boolean generatesWorld() {
return true;
}
@Override
public IWorldGenerator getWorldGenerator() {
return mod;
}
@Override
public int lookupFuelValue(int itemId, int itemDamage) {
return mod.addFuel(itemId, itemDamage);
}
@Override
public boolean wantsPickupNotification() {
return true;
}
@Override
public IPickupNotifier getPickupNotifier() {
return mod;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsToDispense()
*/
@Override
public boolean wantsToDispense() {
return true;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getDispenseHandler()
*/
@Override
public IDispenseHandler getDispenseHandler() {
return mod;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification()
*/
@Override
public boolean wantsCraftingNotification() {
return true;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getCraftingHandler()
*/
@Override
public ICraftingHandler getCraftingHandler() {
return mod;
}
private void computeDependencies() {
dependencies = new ArrayList<String>();
preDependencies = new ArrayList<String>();
postDependencies = new ArrayList<String>();
if (mod.getPriorities()==null || mod.getPriorities().length()==0) {
return;
@Override
public void tickEnd()
{
// NOOP for modloader
}
StringTokenizer st=new StringTokenizer(mod.getPriorities(),";");
for (; st.hasMoreTokens(); ) {
String dep=st.nextToken();
String[] depparts=dep.split(":");
if (depparts.length<2) {
throw new LoaderException();
}
if ("required-before".equals(depparts[0]) || "required-after".equals(depparts[0])) {
dependencies.add(depparts[1]);
}
if ("required-before".equals(depparts[0]) || "before".equals(depparts[0])) {
preDependencies.add(depparts[1]);
}
if ("required-after".equals(depparts[0]) || "after".equals(depparts[0])) {
postDependencies.add(depparts[1]);
}
@Override
public String getName()
{
return mod != null ? mod.getName() : null;
}
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getDependencies()
*/
@Override
public List<String> getDependencies() {
if (dependencies==null) {
computeDependencies();
public static ModContainer findContainerFor(BaseMod mod)
{
for (ModContainer mc : Loader.getModList())
{
if (mc.matches(mod))
{
return mc;
}
}
return null;
}
return dependencies;
}
@Override
public List<String> getPreDepends() {
if (dependencies==null) {
computeDependencies();
@Override
public boolean matches(Object mod)
{
return modClazz.isInstance(mod);
}
return preDependencies;
}
@Override
public List<String> getPostDepends() {
if (dependencies==null) {
computeDependencies();
public void setTicking(boolean enable)
{
isTicking = enable;
}
return postDependencies;
}
public String toString() {
return modSource;
}
@Override
public boolean wantsNetworkPackets() {
return true;
}
public static List<BaseMod> findAll()
{
ArrayList<BaseMod> modList = new ArrayList<BaseMod>();
@Override
public INetworkHandler getNetworkHandler() {
return mod;
}
for (ModContainer mc : Loader.getModList())
{
if (mc instanceof ModLoaderModContainer)
{
modList.add(((ModLoaderModContainer)mc).mod);
}
}
@Override
public boolean ownsNetworkChannel(String channel) {
return FMLHooks.instance().getChannelListFor(this).contains(channel);
}
return modList;
}
@Override
public String getSource()
{
return modSource;
}
@Override
public Object getMod()
{
return mod;
}
@Override
public boolean generatesWorld()
{
return true;
}
@Override
public IWorldGenerator getWorldGenerator()
{
return mod;
}
@Override
public int lookupFuelValue(int itemId, int itemDamage)
{
return mod.addFuel(itemId, itemDamage);
}
@Override
public boolean wantsPickupNotification()
{
return true;
}
@Override
public IPickupNotifier getPickupNotifier()
{
return mod;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsToDispense()
*/
@Override
public boolean wantsToDispense()
{
return true;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getDispenseHandler()
*/
@Override
public IDispenseHandler getDispenseHandler()
{
return mod;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification()
*/
@Override
public boolean wantsCraftingNotification()
{
return true;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getCraftingHandler()
*/
@Override
public ICraftingHandler getCraftingHandler()
{
return mod;
}
private void computeDependencies()
{
dependencies = new ArrayList<String>();
preDependencies = new ArrayList<String>();
postDependencies = new ArrayList<String>();
if (mod.getPriorities() == null || mod.getPriorities().length() == 0)
{
return;
}
StringTokenizer st = new StringTokenizer(mod.getPriorities(), ";");
for (; st.hasMoreTokens();)
{
String dep = st.nextToken();
String[] depparts = dep.split(":");
if (depparts.length < 2)
{
throw new LoaderException();
}
if ("required-before".equals(depparts[0]) || "required-after".equals(depparts[0]))
{
dependencies.add(depparts[1]);
}
if ("required-before".equals(depparts[0]) || "before".equals(depparts[0]))
{
preDependencies.add(depparts[1]);
}
if ("required-after".equals(depparts[0]) || "after".equals(depparts[0]))
{
postDependencies.add(depparts[1]);
}
}
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.ModContainer#getDependencies()
*/
@Override
public List<String> getDependencies()
{
if (dependencies == null)
{
computeDependencies();
}
return dependencies;
}
@Override
public List<String> getPreDepends()
{
if (dependencies == null)
{
computeDependencies();
}
return preDependencies;
}
@Override
public List<String> getPostDepends()
{
if (dependencies == null)
{
computeDependencies();
}
return postDependencies;
}
public String toString()
{
return modSource;
}
@Override
public boolean wantsNetworkPackets()
{
return true;
}
@Override
public INetworkHandler getNetworkHandler()
{
return mod;
}
@Override
public boolean ownsNetworkChannel(String channel)
{
return FMLHooks.instance().getChannelListFor(this).contains(channel);
}
}
+237 -211
View File
@@ -1,12 +1,12 @@
/*
* 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
*/
@@ -21,230 +21,256 @@ import cpw.mods.fml.common.INetworkHandler;
import cpw.mods.fml.common.IPickupNotifier;
import cpw.mods.fml.common.IWorldGenerator;
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler {
// CALLBACK MECHANISMS
@Override
public final void onCrafting(Object... craftingParameters) {
takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]);
}
@Override
public final void onSmelting(Object... smeltingParameters) {
takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]);
}
@Override
public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data) {
return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]);
}
@Override
public final boolean onChat(Object... data) {
return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]);
}
@Override
public final void onLogin(Object... data) {
onClientLogin((Packet1Login)data[0],(NetworkManager)data[1]);
}
@Override
public final void onPacket250Packet(Object... data) {
onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]);
}
@Override
public final void notifyPickup(Object... pickupData) {
EntityItem item=(EntityItem) pickupData[0];
EntityPlayer player=(EntityPlayer) pickupData[1];
onItemPickup(player, item.field_429_a);
}
@Override
public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData) {
World w=(World) additionalData[0];
IChunkProvider cp=(IChunkProvider) additionalData[1];
if (cp instanceof ChunkProviderGenerate) {
generateSurface(w, random, chunkX<<4, chunkZ<<4);
} else if (cp instanceof ChunkProviderHell){
generateNether(w, random, chunkX<<4, chunkZ<<4);
public abstract class BaseMod implements IWorldGenerator, IPickupNotifier, IDispenseHandler, ICraftingHandler, INetworkHandler
{
// CALLBACK MECHANISMS
@Override
public final void onCrafting(Object... craftingParameters)
{
takenFromCrafting((EntityPlayer)craftingParameters[0], (ItemStack)craftingParameters[1], (IInventory)craftingParameters[2]);
}
}
// BASEMOD API
/**
* Override if you wish to provide a fuel item for the furnace and return the fuel value of the item
* @param id
* @param metadata
* @return
*/
public int addFuel(int id, int metadata) {
return 0;
}
/**
* Override if you wish to perform some action other than just dispensing the item from the dispenser
* @param world
* @param x
* @param y
* @param z
* @param xVel
* @param zVel
* @param item
* @return
*/
public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item) {
return false;
}
@Override
public final void onSmelting(Object... smeltingParameters)
{
takenFromFurnace((EntityPlayer)smeltingParameters[0], (ItemStack)smeltingParameters[1]);
}
@Override
public final boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data)
{
return dispenseEntity((World)data[0], x, y, z, xVelocity, zVelocity, (ItemStack)data[1]);
}
/**
* Override if you wish to generate Nether (Hell biome) blocks
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
@Override
public final boolean onChat(Object... data)
{
return onChatMessageReceived((EntityPlayer)data[1], (Packet3Chat)data[0]);
}
@Override
public final void onLogin(Object... data)
{
onClientLogin((Packet1Login)data[0], (NetworkManager)data[1]);
}
/**
* Override if you wish to generate Overworld (not hell or the end) blocks
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
}
@Override
public final void onPacket250Packet(Object... data)
{
onPacket250Received((EntityPlayer)data[1], (Packet250CustomPayload)data[0]);
}
/**
* Return the name of your mod. Defaults to the class name
* @return
*/
public String getName() {
return getClass().getSimpleName();
}
@Override
public final void notifyPickup(Object... pickupData)
{
EntityItem item = (EntityItem) pickupData[0];
EntityPlayer player = (EntityPlayer) pickupData[1];
onItemPickup(player, item.field_429_a);
}
/**
* Get your mod priorities
* @return
*/
public String getPriorities() {
return null;
}
@Override
public final void generate(Random random, int chunkX, int chunkZ, Object... additionalData)
{
World w = (World) additionalData[0];
IChunkProvider cp = (IChunkProvider) additionalData[1];
/**
* Return the version of your mod
* @return
*/
public abstract String getVersion();
if (cp instanceof ChunkProviderGenerate)
{
generateSurface(w, random, chunkX << 4, chunkZ << 4);
}
else if (cp instanceof ChunkProviderHell)
{
generateNether(w, random, chunkX << 4, chunkZ << 4);
}
}
/**
* Load your mod
*/
public abstract void load();
// BASEMOD API
/**
* Override if you wish to provide a fuel item for the furnace and return the fuel value of the item
* @param id
* @param metadata
* @return
*/
public int addFuel(int id, int metadata)
{
return 0;
}
/**
* Finish loading your mod
*/
public void modsLoaded() {
}
/**
* Override if you wish to perform some action other than just dispensing the item from the dispenser
* @param world
* @param x
* @param y
* @param z
* @param xVel
* @param zVel
* @param item
* @return
*/
public boolean dispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item)
{
return false;
}
/**
* Handle item pickup
* @param player
* @param item
*/
public void onItemPickup(EntityPlayer player, ItemStack item) {
}
/**
* Override if you wish to generate Nether (Hell biome) blocks
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateNether(World world, Random random, int chunkX, int chunkZ)
{
}
/**
* Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)}
* @param minecraftServer the server
* @return true to continue receiving ticks
*/
public boolean onTickInGame(MinecraftServer minecraftServer) {
return false;
}
/**
* Override if you wish to generate Overworld (not hell or the end) blocks
* @param world
* @param random
* @param chunkX
* @param chunkZ
*/
public void generateSurface(World world, Random random, int chunkX, int chunkZ)
{
}
/**
* Not implemented because on the server you don't know who it's from
* {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)}
* @param text
*/
@Deprecated
public void receiveChatPacket(String text) {
}
/**
* Return the name of your mod. Defaults to the class name
* @return
*/
public String getName()
{
return getClass().getSimpleName();
}
/**
* Not implemented because on the server you don't know who it's from
* {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)}
* @param packet
*/
@Deprecated
public void receiveCustomPacket(Packet250CustomPayload packet) {
}
/**
* Get your mod priorities
* @return
*/
public String getPriorities()
{
return null;
}
/**
* Called when someone crafts an item from a crafting table
* @param player
* @param item
* @param matrix
*/
public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix) {
}
/**
* Return the version of your mod
* @return
*/
public abstract String getVersion();
/**
* Called when someone takes a smelted item from a furnace
*
* @param player
* @param item
*/
public void takenFromFurnace(EntityPlayer player, ItemStack item) {
/**
* Load your mod
*/
public abstract void load();
}
/**
* Finish loading your mod
*/
public void modsLoaded()
{
}
/**
* The identifier string for the mod- used in client<->server negotiation
*/
@Override
public String toString() {
return getName()+" "+getVersion();
}
/**
* Handle item pickup
* @param player
* @param item
*/
public void onItemPickup(EntityPlayer player, ItemStack item)
{
}
/**
* Called when a 250 packet is received on a channel registered to this mod
*
* @param source
* @param payload
*/
public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) {
}
/**
* Called when a new client logs in. Make sure modloader knows about your channels
* @param login
* @param data
*/
public void onClientLogin(Packet1Login login, NetworkManager data) {
}
/**
* Called when a chat message is received. Return true to stop further processing
* @param source
* @param chat
* @return
*/
public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) {
return false;
}
// Spare client junk
// -------
// void addRenderer(Map<Class<? extends Entity>, Render> renderers);
// void registerAnimation(Minecraft game);
// void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID);
// boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID);
// boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui);
// void keyboardEvent(KeyBinding event);
/**
* Ticked every game tick if you have subscribed to tick events through {@link ModLoader#setInGameHook(BaseMod, boolean, boolean)}
* @param minecraftServer the server
* @return true to continue receiving ticks
*/
public boolean onTickInGame(MinecraftServer minecraftServer)
{
return false;
}
/**
* Not implemented because on the server you don't know who it's from
* {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)}
* @param text
*/
@Deprecated
public void receiveChatPacket(String text)
{
}
/**
* Not implemented because on the server you don't know who it's from
* {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)}
* @param packet
*/
@Deprecated
public void receiveCustomPacket(Packet250CustomPayload packet)
{
}
/**
* Called when someone crafts an item from a crafting table
* @param player
* @param item
* @param matrix
*/
public void takenFromCrafting(EntityPlayer player, ItemStack item, IInventory matrix)
{
}
/**
* Called when someone takes a smelted item from a furnace
*
* @param player
* @param item
*/
public void takenFromFurnace(EntityPlayer player, ItemStack item)
{
}
/**
* The identifier string for the mod- used in client<->server negotiation
*/
@Override
public String toString()
{
return getName() + " " + getVersion();
}
/**
* Called when a 250 packet is received on a channel registered to this mod
*
* @param source
* @param payload
*/
public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload)
{
}
/**
* Called when a new client logs in. Make sure modloader knows about your channels
* @param login
* @param data
*/
public void onClientLogin(Packet1Login login, NetworkManager data)
{
}
/**
* Called when a chat message is received. Return true to stop further processing
* @param source
* @param chat
* @return
*/
public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat)
{
return false;
}
// Spare client junk
// -------
// void addRenderer(Map<Class<? extends Entity>, Render> renderers);
// void registerAnimation(Minecraft game);
// void renderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID);
// boolean renderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID);
// boolean onTickInGUI(float tick, Minecraft game, GuiScreen gui);
// void keyboardEvent(KeyBinding event);
}
+22 -21
View File
@@ -1,12 +1,12 @@
/*
* 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
*/
@@ -19,29 +19,30 @@ import static java.lang.annotation.ElementType.*;
/**
* @author cpw
*
*
*/
@Retention(value = RUNTIME)
@Target(value = FIELD)
public @interface MLProp {
/**
* Adds additional help to top of configuration file.
*/
String info() default "";
public @interface MLProp
{
/**
* Adds additional help to top of configuration file.
*/
String info() default "";
/**
* Maximum value allowed if field is a number.
*/
double max() default 1D;
/**
* Maximum value allowed if field is a number.
*/
double max() default 1D;
/**
* Minimum value allowed if field is a number.
*/
double min() default -1D;
/**
* Minimum value allowed if field is a number.
*/
double min() default -1D;
/**
* Overrides the field name for property key.
*/
String name() default "";
/**
* Overrides the field name for property key.
*/
String name() default "";
}
File diff suppressed because it is too large. Load diff