Run Astyle over the FML code. Happy lex?
This commit is contained in:
parent
011dd869de
commit
e828c1793d
|
@ -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
|
||||
*/
|
||||
|
@ -23,102 +23,132 @@ import net.minecraft.src.EntityPlayer;
|
|||
|
||||
|
||||
|
||||
public class FMLHooks {
|
||||
private static final FMLHooks INSTANCE=new FMLHooks();
|
||||
private Map<ModContainer,Set<String>> channelList=new HashMap<ModContainer,Set<String>>();
|
||||
private Map<String,ModContainer> modChannels=new HashMap<String,ModContainer>();
|
||||
private Map<Object,Set<String>> activeChannels=new HashMap<Object,Set<String>>();
|
||||
|
||||
public void gameTickStart() {
|
||||
for (ModContainer mod : Loader.getModList()) {
|
||||
mod.tickStart();
|
||||
}
|
||||
}
|
||||
|
||||
public void gameTickEnd() {
|
||||
for (ModContainer mod : Loader.getModList()) {
|
||||
mod.tickEnd();
|
||||
}
|
||||
}
|
||||
public class FMLHooks
|
||||
{
|
||||
private static final FMLHooks INSTANCE = new FMLHooks();
|
||||
private Map<ModContainer, Set<String>> channelList = new HashMap<ModContainer, Set<String>>();
|
||||
private Map<String, ModContainer> modChannels = new HashMap<String, ModContainer>();
|
||||
private Map<Object, Set<String>> activeChannels = new HashMap<Object, Set<String>>();
|
||||
|
||||
/**
|
||||
* @return the instance
|
||||
*/
|
||||
public static FMLHooks instance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
public void gameTickStart()
|
||||
{
|
||||
for (ModContainer mod : Loader.getModList())
|
||||
{
|
||||
mod.tickStart();
|
||||
}
|
||||
}
|
||||
|
||||
public ModContainer getModForChannel(String channel) {
|
||||
return modChannels.get(channel);
|
||||
}
|
||||
/**
|
||||
* @param modLoaderModContainer
|
||||
* @return
|
||||
*/
|
||||
public Set<String> getChannelListFor(ModContainer container) {
|
||||
return channelList.get(container);
|
||||
}
|
||||
|
||||
public void registerChannel(ModContainer container, String channelName) {
|
||||
if (modChannels.containsKey(channelName)) {
|
||||
// NOOP
|
||||
public void gameTickEnd()
|
||||
{
|
||||
for (ModContainer mod : Loader.getModList())
|
||||
{
|
||||
mod.tickEnd();
|
||||
}
|
||||
}
|
||||
Set<String> list=channelList.get(container);
|
||||
if (list==null) {
|
||||
list=new HashSet<String>();
|
||||
channelList.put(container, list);
|
||||
}
|
||||
list.add(channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
*/
|
||||
public void activateChannel(Object player, String channel) {
|
||||
Set<String> active=activeChannels.get(player);
|
||||
if (active==null) {
|
||||
active=new HashSet<String>();
|
||||
activeChannels.put(player, active);
|
||||
/**
|
||||
* @return the instance
|
||||
*/
|
||||
public static FMLHooks instance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
active.add(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param channel
|
||||
*/
|
||||
public void deactivateChannel(EntityPlayer player, String channel) {
|
||||
Set<String> active=activeChannels.get(player);
|
||||
if (active==null) {
|
||||
active=new HashSet<String>();
|
||||
activeChannels.put(player, active);
|
||||
public ModContainer getModForChannel(String channel)
|
||||
{
|
||||
return modChannels.get(channel);
|
||||
}
|
||||
/**
|
||||
* @param modLoaderModContainer
|
||||
* @return
|
||||
*/
|
||||
public Set<String> getChannelListFor(ModContainer container)
|
||||
{
|
||||
return channelList.get(container);
|
||||
}
|
||||
active.remove(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public byte[] getPacketRegistry() {
|
||||
StringBuffer sb=new StringBuffer();
|
||||
for (String chan : modChannels.keySet()) {
|
||||
sb.append(chan).append("\0");
|
||||
}
|
||||
try {
|
||||
return sb.toString().getBytes("UTF8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Loader.log.warning("Error building registration list");
|
||||
Loader.log.throwing("FMLHooks", "getPacketRegistry", e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
public void registerChannel(ModContainer container, String channelName)
|
||||
{
|
||||
if (modChannels.containsKey(channelName))
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean isChannelActive(String channel, Object player) {
|
||||
return activeChannels.get(player).contains(channel);
|
||||
}
|
||||
Set<String> list = channelList.get(container);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
list = new HashSet<String>();
|
||||
channelList.put(container, list);
|
||||
}
|
||||
|
||||
list.add(channelName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
*/
|
||||
public void activateChannel(Object player, String channel)
|
||||
{
|
||||
Set<String> active = activeChannels.get(player);
|
||||
|
||||
if (active == null)
|
||||
{
|
||||
active = new HashSet<String>();
|
||||
activeChannels.put(player, active);
|
||||
}
|
||||
|
||||
active.add(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param channel
|
||||
*/
|
||||
public void deactivateChannel(EntityPlayer player, String channel)
|
||||
{
|
||||
Set<String> active = activeChannels.get(player);
|
||||
|
||||
if (active == null)
|
||||
{
|
||||
active = new HashSet<String>();
|
||||
activeChannels.put(player, active);
|
||||
}
|
||||
|
||||
active.remove(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public byte[] getPacketRegistry()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (String chan : modChannels.keySet())
|
||||
{
|
||||
sb.append(chan).append("\0");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return sb.toString().getBytes("UTF8");
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
Loader.log.warning("Error building registration list");
|
||||
Loader.log.throwing("FMLHooks", "getPacketRegistry", e);
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param channel
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public boolean isChannelActive(String channel, Object player)
|
||||
{
|
||||
return activeChannels.get(player).contains(channel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -15,219 +15,250 @@ package cpw.mods.fml.common;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FMLModContainer implements ModContainer {
|
||||
private Mod modDescriptor;
|
||||
private Object modInstance;
|
||||
private String source;
|
||||
public class FMLModContainer implements ModContainer
|
||||
{
|
||||
private Mod modDescriptor;
|
||||
private Object modInstance;
|
||||
private String source;
|
||||
|
||||
public FMLModContainer(String source) {
|
||||
this.source=source;
|
||||
}
|
||||
|
||||
public FMLModContainer(Class<?> clazz) {
|
||||
if (clazz==null) {
|
||||
return;
|
||||
public FMLModContainer(String source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
modDescriptor = clazz.getAnnotation(Mod.class);
|
||||
|
||||
try {
|
||||
modInstance = clazz.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
public FMLModContainer(Class<?> clazz)
|
||||
{
|
||||
if (clazz == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
modDescriptor = clazz.getAnnotation(Mod.class);
|
||||
|
||||
try
|
||||
{
|
||||
modInstance = clazz.newInstance();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsPreInit() {
|
||||
return modDescriptor.wantsPreInit();
|
||||
}
|
||||
@Override
|
||||
public boolean wantsPreInit()
|
||||
{
|
||||
return modDescriptor.wantsPreInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsPostInit() {
|
||||
return modDescriptor.wantsPostInit();
|
||||
}
|
||||
@Override
|
||||
public boolean wantsPostInit()
|
||||
{
|
||||
return modDescriptor.wantsPostInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit() {
|
||||
@Override
|
||||
public void preInit()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public void postInit()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
||||
public static ModContainer buildFor(Class<?> clazz)
|
||||
{
|
||||
return new FMLModContainer(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void tickStart()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public static ModContainer buildFor(Class<?> clazz) {
|
||||
return new FMLModContainer(clazz);
|
||||
}
|
||||
@Override
|
||||
public void tickEnd()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean matches(Object mod)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickStart() {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public String getSource()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public Object getMod()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd() {
|
||||
// TODO Auto-generated method stub
|
||||
@Override
|
||||
public boolean generatesWorld()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public IWorldGenerator getWorldGenerator()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object mod) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int lookupFuelValue(int itemId, int itemDamage)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSource() {
|
||||
return source;
|
||||
}
|
||||
@Override
|
||||
public boolean wantsPickupNotification()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMod() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IPickupNotifier getPickupNotifier()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generatesWorld() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsToDispense()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsToDispense()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldGenerator getWorldGenerator() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getDispenseHandler()
|
||||
*/
|
||||
@Override
|
||||
public IDispenseHandler getDispenseHandler()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lookupFuelValue(int itemId, int itemDamage) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsCraftingNotification()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wantsPickupNotification() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getCraftingHandler()
|
||||
*/
|
||||
@Override
|
||||
public ICraftingHandler getCraftingHandler()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPickupNotifier getPickupNotifier() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getDependencies()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getDependencies()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsToDispense()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsToDispense() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getPreDepends()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPreDepends()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getDispenseHandler()
|
||||
*/
|
||||
@Override
|
||||
public IDispenseHandler getDispenseHandler() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getPostDepends()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPostDepends()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsCraftingNotification()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsCraftingNotification() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getSource();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getCraftingHandler()
|
||||
*/
|
||||
@Override
|
||||
public ICraftingHandler getCraftingHandler() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsNetworkPackets()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsNetworkPackets()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getDependencies()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getDependencies() {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getNetworkHandler()
|
||||
*/
|
||||
@Override
|
||||
public INetworkHandler getNetworkHandler()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getPreDepends()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPreDepends() {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getPostDepends()
|
||||
*/
|
||||
@Override
|
||||
public List<String> getPostDepends() {
|
||||
// TODO Auto-generated method stub
|
||||
return new ArrayList<String>(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSource();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#wantsNetworkPackets()
|
||||
*/
|
||||
@Override
|
||||
public boolean wantsNetworkPackets() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getNetworkHandler()
|
||||
*/
|
||||
@Override
|
||||
public INetworkHandler getNetworkHandler() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#ownsNetworkChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean ownsNetworkChannel(String channel) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#ownsNetworkChannel(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean ownsNetworkChannel(String channel)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -17,18 +17,19 @@ package cpw.mods.fml.common;
|
|||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public interface ICraftingHandler {
|
||||
public interface ICraftingHandler
|
||||
{
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param craftedItem
|
||||
* @param craftingGrid
|
||||
*/
|
||||
void onCrafting(Object... craftingParameters);
|
||||
/**
|
||||
* @param player
|
||||
* @param craftedItem
|
||||
* @param craftingGrid
|
||||
*/
|
||||
void onCrafting(Object... craftingParameters);
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param smeltedItem
|
||||
*/
|
||||
void onSmelting(Object... smeltingParameters);
|
||||
/**
|
||||
* @param player
|
||||
* @param smeltedItem
|
||||
*/
|
||||
void onSmelting(Object... smeltingParameters);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
/*
|
||||
* 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 cpw.mods.fml.common;
|
||||
|
||||
|
||||
public interface IDispenseHandler {
|
||||
boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data);
|
||||
public interface IDispenseHandler
|
||||
{
|
||||
boolean dispense(double x, double y, double z, byte xVelocity, byte zVelocity, Object... data);
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -15,10 +15,11 @@ package cpw.mods.fml.common;
|
|||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface INetworkHandler {
|
||||
boolean onChat(Object... data);
|
||||
void onPacket250Packet(Object... data);
|
||||
void onLogin(Object... data);
|
||||
public interface INetworkHandler
|
||||
{
|
||||
boolean onChat(Object... data);
|
||||
void onPacket250Packet(Object... data);
|
||||
void onLogin(Object... data);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
/*
|
||||
* 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 cpw.mods.fml.common;
|
||||
|
||||
public interface IPickupNotifier {
|
||||
void notifyPickup(Object... pickupData);
|
||||
public interface IPickupNotifier
|
||||
{
|
||||
void notifyPickup(Object... pickupData);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ package cpw.mods.fml.common;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
public interface IWorldGenerator {
|
||||
public void generate(Random random, int chunkX, int chunkZ, Object...additionalData);
|
||||
public interface IWorldGenerator
|
||||
{
|
||||
public void generate(Random random, int chunkX, int chunkZ, Object...additionalData);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -34,303 +34,408 @@ import java.util.zip.ZipFile;
|
|||
import cpw.mods.fml.common.toposort.ModSorter;
|
||||
import cpw.mods.fml.server.FMLHandler;
|
||||
|
||||
public class Loader {
|
||||
private enum State {
|
||||
NOINIT, LOADING, PREINIT, INIT, POSTINIT, UP, ERRORED
|
||||
};
|
||||
public class Loader
|
||||
{
|
||||
private enum State
|
||||
{
|
||||
NOINIT, LOADING, PREINIT, INIT, POSTINIT, UP, ERRORED
|
||||
};
|
||||
|
||||
private static Loader instance;
|
||||
public static Logger log = Logger.getLogger("ForgeModLoader");
|
||||
private static Loader instance;
|
||||
public static Logger log = Logger.getLogger("ForgeModLoader");
|
||||
|
||||
private static Pattern zipJar = Pattern.compile("([^\\s]+).(zip|jar)$");
|
||||
private static Pattern modClass = Pattern.compile("(.*/?)(mod\\_[^\\s]+).class$");
|
||||
private static Pattern zipJar = Pattern.compile("([^\\s]+).(zip|jar)$");
|
||||
private static Pattern modClass = Pattern.compile("(.*/?)(mod\\_[^\\s]+).class$");
|
||||
|
||||
private static String major="@MAJOR@";
|
||||
private static String minor="@MINOR@";
|
||||
private static String rev ="@REV@";
|
||||
private static String build="@BUILD@";
|
||||
private static String mcversion="@MCVERSION@";
|
||||
|
||||
private State state;
|
||||
private ModClassLoader modClassLoader;
|
||||
private List<ModContainer> mods;
|
||||
private Map<String,ModContainer> namedMods;
|
||||
private File canonicalConfigDir;
|
||||
private File canonicalMinecraftDir;
|
||||
private static String major = "@MAJOR@";
|
||||
private static String minor = "@MINOR@";
|
||||
private static String rev = "@REV@";
|
||||
private static String build = "@BUILD@";
|
||||
private static String mcversion = "@MCVERSION@";
|
||||
|
||||
public static Loader instance() {
|
||||
if (instance==null) {
|
||||
instance=new Loader();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
private Loader() {
|
||||
Loader.log.setParent(FMLHandler.getMinecraftLogger());
|
||||
Loader.log.setLevel(Level.ALL);
|
||||
FileHandler fileHandler;
|
||||
try {
|
||||
fileHandler = new FileHandler("ForgeModLoader-%g.log", 0, 3);
|
||||
// We're stealing minecraft's log formatter
|
||||
fileHandler.setFormatter(FMLHandler.getMinecraftLogger().getHandlers()[0].getFormatter());
|
||||
fileHandler.setLevel(Level.ALL);
|
||||
Loader.log.addHandler(fileHandler);
|
||||
} catch (Exception e) {
|
||||
// Whatever - give up
|
||||
}
|
||||
log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft %s loading",major,minor,rev,build,mcversion));
|
||||
}
|
||||
private State state;
|
||||
private ModClassLoader modClassLoader;
|
||||
private List<ModContainer> mods;
|
||||
private Map<String, ModContainer> namedMods;
|
||||
private File canonicalConfigDir;
|
||||
private File canonicalMinecraftDir;
|
||||
|
||||
private void sortModList() {
|
||||
log.fine("Verifying mod dependencies are satisfied");
|
||||
for (ModContainer mod : mods) {
|
||||
if (!namedMods.keySet().containsAll(mod.getDependencies())) {
|
||||
log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(),mod.getDependencies()));
|
||||
LoaderException le=new LoaderException();
|
||||
log.throwing("Loader", "sortModList", le);
|
||||
throw new LoaderException();
|
||||
}
|
||||
}
|
||||
log.fine("All dependencies are satisfied");
|
||||
ModSorter sorter=new ModSorter(mods,namedMods);
|
||||
try {
|
||||
log.fine("Sorting mods into an ordered list");
|
||||
mods=sorter.sort();
|
||||
log.fine(String.format("Mod list sorted %s",mods));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
log.severe("A dependency cycle was detected in the input mod set so they cannot load them in order");
|
||||
log.throwing("Loader", "sortModList", iae);
|
||||
throw new LoaderException(iae);
|
||||
}
|
||||
}
|
||||
|
||||
private void preModInit() {
|
||||
state = State.PREINIT;
|
||||
log.fine("Beginning mod pre-initialization");
|
||||
for (ModContainer mod : mods) {
|
||||
if (mod.wantsPreInit()) {
|
||||
log.finer(String.format("Pre-initializing %s", mod.getSource()));
|
||||
mod.preInit();
|
||||
namedMods.put(mod.getName(), mod);
|
||||
}
|
||||
}
|
||||
log.fine("Mod pre-initialization complete");
|
||||
}
|
||||
|
||||
private void modInit() {
|
||||
state = State.INIT;
|
||||
log.fine("Beginning mod initialization");
|
||||
for (ModContainer mod : mods) {
|
||||
log.finer(String.format("Initializing %s", mod.getName()));
|
||||
mod.init();
|
||||
}
|
||||
log.fine("Mod initialization complete");
|
||||
}
|
||||
|
||||
private void postModInit() {
|
||||
state = State.POSTINIT;
|
||||
log.fine("Beginning mod post-initialization");
|
||||
for (ModContainer mod : mods) {
|
||||
if (mod.wantsPostInit()) {
|
||||
log.finer(String.format("Post-initializing %s", mod.getName()));
|
||||
mod.postInit();
|
||||
}
|
||||
}
|
||||
log.fine("Mod post-initialization complete");
|
||||
}
|
||||
|
||||
private void load() {
|
||||
File minecraftDir = new File(".");
|
||||
File modsDir = new File(minecraftDir, "mods");
|
||||
File configDir=new File(minecraftDir, "config");
|
||||
String canonicalModsPath;
|
||||
String canonicalConfigPath;
|
||||
try {
|
||||
canonicalMinecraftDir=minecraftDir.getCanonicalFile();
|
||||
canonicalModsPath = modsDir.getCanonicalPath();
|
||||
canonicalConfigPath=configDir.getCanonicalPath();
|
||||
canonicalConfigDir=configDir.getCanonicalFile();
|
||||
} catch (IOException ioe) {
|
||||
log.severe(String.format("Failed to resolve mods directory mods %s", modsDir.getAbsolutePath()));
|
||||
log.throwing("fml.server.Loader", "initialize", ioe);
|
||||
throw new LoaderException(ioe);
|
||||
}
|
||||
if (!modsDir.exists()) {
|
||||
log.fine(String.format("No mod directory found, creating one: %s", canonicalModsPath));
|
||||
try {
|
||||
modsDir.mkdir();
|
||||
} catch (Exception e) {
|
||||
log.throwing("fml.server.Loader", "initialize", e);
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
if (!configDir.exists()) {
|
||||
log.fine(String.format("No config directory found, creating one: %s", canonicalConfigPath));
|
||||
try {
|
||||
configDir.mkdir();
|
||||
} catch (Exception e) {
|
||||
log.throwing("fml.server.Loader", "initialize", e);
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
if (!modsDir.isDirectory()) {
|
||||
log.severe(String.format("Attempting to load mods from %s, which is not a directory", canonicalModsPath));
|
||||
LoaderException loaderException = new LoaderException();
|
||||
log.throwing("fml.server.Loader", "initialize", loaderException);
|
||||
throw loaderException;
|
||||
}
|
||||
if (!configDir.isDirectory()) {
|
||||
log.severe(String.format("Attempting to load configuration from %s, which is not a directory", canonicalConfigPath));
|
||||
LoaderException loaderException = new LoaderException();
|
||||
log.throwing("fml.server.Loader", "initialize", loaderException);
|
||||
throw loaderException;
|
||||
}
|
||||
|
||||
log.fine("Attempting to load mods contained in the minecraft jar file");
|
||||
attemptFileLoad(new File(minecraftDir,"minecraft_server.jar"));
|
||||
log.fine("Minecraft jar mods loaded successfully");
|
||||
|
||||
log.info(String.format("Loading mods from %s",canonicalModsPath));
|
||||
File[] modList = modsDir.listFiles();
|
||||
// Sort the files into alphabetical order first
|
||||
Arrays.sort(modList);
|
||||
|
||||
state = State.LOADING;
|
||||
for (File modFile : modList) {
|
||||
if (modFile.isDirectory()) {
|
||||
log.fine(String.format("Found a directory %s, attempting to load it", modFile.getName()));
|
||||
boolean modFound=attemptDirLoad(modFile);
|
||||
if (modFound) {
|
||||
log.fine(String.format("Directory %s loaded successfully", modFile.getName()));
|
||||
} else {
|
||||
log.info(String.format("Directory %s contained no mods", modFile.getName()));
|
||||
public static Loader instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new Loader();
|
||||
}
|
||||
} else {
|
||||
Matcher matcher = zipJar.matcher(modFile.getName());
|
||||
if (matcher.matches()) {
|
||||
log.fine(String.format("Found a zip or jar file %s, attempting to load it", matcher.group(0)));
|
||||
boolean modFound=attemptFileLoad(modFile);
|
||||
if (modFound) {
|
||||
log.fine(String.format("File %s loaded successfully", matcher.group(0)));
|
||||
} else {
|
||||
log.info(String.format("File %s contained no mods", matcher.group(0)));
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
private Loader()
|
||||
{
|
||||
Loader.log.setParent(FMLHandler.getMinecraftLogger());
|
||||
Loader.log.setLevel(Level.ALL);
|
||||
FileHandler fileHandler;
|
||||
|
||||
try
|
||||
{
|
||||
fileHandler = new FileHandler("ForgeModLoader-%g.log", 0, 3);
|
||||
// We're stealing minecraft's log formatter
|
||||
fileHandler.setFormatter(FMLHandler.getMinecraftLogger().getHandlers()[0].getFormatter());
|
||||
fileHandler.setLevel(Level.ALL);
|
||||
Loader.log.addHandler(fileHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state == State.ERRORED) {
|
||||
log.severe("A problem has occured during mod loading, giving up now");
|
||||
throw new RuntimeException("Giving up please");
|
||||
}
|
||||
log.info(String.format("Forge Mod Loader has loaded %d mods",mods.size()));
|
||||
}
|
||||
|
||||
private boolean attemptDirLoad(File modDir) {
|
||||
extendClassLoader(modDir);
|
||||
|
||||
boolean foundAModClass=false;
|
||||
File[] content = modDir.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return modClass.matcher(name).find();
|
||||
}
|
||||
});
|
||||
for (File modClassFile : content) {
|
||||
String clazzName = modClass.matcher(modClassFile.getName()).group(2);
|
||||
log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName()));
|
||||
loadModClass(modDir, modClassFile.getName(), clazzName);
|
||||
log.fine(String.format("Successfully loaded mod class %s", modClassFile.getName()));
|
||||
foundAModClass=true;
|
||||
}
|
||||
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
private void loadModClass(File classSource, String classFileName, String clazzName) {
|
||||
try {
|
||||
Class<?> clazz = Class.forName(clazzName, false, modClassLoader);
|
||||
if (clazz.isAnnotationPresent(Mod.class)) {
|
||||
// an FML mod
|
||||
mods.add(FMLModContainer.buildFor(clazz));
|
||||
} else if (FMLHandler.instance().isModLoaderMod(clazz)) {
|
||||
log.fine(String.format("ModLoader BaseMod class %s found, loading", clazzName));
|
||||
ModContainer mc=FMLHandler.instance().loadBaseModMod(clazz,classSource.getCanonicalPath());
|
||||
mods.add(mc);
|
||||
log.fine(String.format("ModLoader BaseMod class %s loaded", clazzName));
|
||||
} else {
|
||||
// Unrecognized
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warning(String.format("Failed to load mod class %s in %s", classFileName, classSource.getAbsoluteFile()));
|
||||
log.throwing("fml.server.Loader", "attemptLoad", e);
|
||||
state = State.ERRORED;
|
||||
}
|
||||
}
|
||||
|
||||
private void extendClassLoader(File file) {
|
||||
if (modClassLoader == null) {
|
||||
modClassLoader = new ModClassLoader();
|
||||
}
|
||||
try {
|
||||
modClassLoader.addFile(file);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean attemptFileLoad(File modFile) {
|
||||
extendClassLoader(modFile);
|
||||
|
||||
boolean foundAModClass=false;
|
||||
try {
|
||||
ZipFile jar = new ZipFile(modFile);
|
||||
for (ZipEntry ze : Collections.list(jar.entries())) {
|
||||
Matcher match = modClass.matcher(ze.getName());
|
||||
if (match.matches()) {
|
||||
String pkg = match.group(1).replace('/', '.');
|
||||
String clazzName = pkg + match.group(2);
|
||||
log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName()));
|
||||
loadModClass(modFile, ze.getName(), clazzName);
|
||||
log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName()));
|
||||
foundAModClass=true;
|
||||
catch (Exception e)
|
||||
{
|
||||
// Whatever - give up
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warning(String.format("Zip file %s failed to read properly", modFile.getName()));
|
||||
log.throwing("fml.server.Loader", "attemptFileLoad", e);
|
||||
state = State.ERRORED;
|
||||
|
||||
log.info(String.format("Forge Mod Loader version %s.%s.%s.%s for Minecraft %s loading", major, minor, rev, build, mcversion));
|
||||
}
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
public static List<ModContainer> getModList() {
|
||||
return instance().mods;
|
||||
}
|
||||
private void sortModList()
|
||||
{
|
||||
log.fine("Verifying mod dependencies are satisfied");
|
||||
|
||||
public void loadMods() {
|
||||
state = State.NOINIT;
|
||||
mods = new ArrayList<ModContainer>();
|
||||
namedMods = new HashMap<String,ModContainer>();
|
||||
load();
|
||||
preModInit();
|
||||
sortModList();
|
||||
// Make mod list immutable
|
||||
mods=Collections.unmodifiableList(mods);
|
||||
}
|
||||
for (ModContainer mod : mods)
|
||||
{
|
||||
if (!namedMods.keySet().containsAll(mod.getDependencies()))
|
||||
{
|
||||
log.severe(String.format("The mod %s requires mods %s to be available, one or more are not", mod.getName(), mod.getDependencies()));
|
||||
LoaderException le = new LoaderException();
|
||||
log.throwing("Loader", "sortModList", le);
|
||||
throw new LoaderException();
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeMods() {
|
||||
modInit();
|
||||
postModInit();
|
||||
state = State.UP;
|
||||
log.info(String.format("Forge Mod Loader load complete, %d mods loaded",mods.size()));
|
||||
}
|
||||
|
||||
public static boolean isModLoaded(String modname) {
|
||||
return instance().namedMods.containsKey(modname);
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public File getConfigDir() {
|
||||
return canonicalConfigDir;
|
||||
}
|
||||
log.fine("All dependencies are satisfied");
|
||||
ModSorter sorter = new ModSorter(mods, namedMods);
|
||||
|
||||
try
|
||||
{
|
||||
log.fine("Sorting mods into an ordered list");
|
||||
mods = sorter.sort();
|
||||
log.fine(String.format("Mod list sorted %s", mods));
|
||||
}
|
||||
catch (IllegalArgumentException iae)
|
||||
{
|
||||
log.severe("A dependency cycle was detected in the input mod set so they cannot load them in order");
|
||||
log.throwing("Loader", "sortModList", iae);
|
||||
throw new LoaderException(iae);
|
||||
}
|
||||
}
|
||||
|
||||
private void preModInit()
|
||||
{
|
||||
state = State.PREINIT;
|
||||
log.fine("Beginning mod pre-initialization");
|
||||
|
||||
for (ModContainer mod : mods)
|
||||
{
|
||||
if (mod.wantsPreInit())
|
||||
{
|
||||
log.finer(String.format("Pre-initializing %s", mod.getSource()));
|
||||
mod.preInit();
|
||||
namedMods.put(mod.getName(), mod);
|
||||
}
|
||||
}
|
||||
|
||||
log.fine("Mod pre-initialization complete");
|
||||
}
|
||||
|
||||
private void modInit()
|
||||
{
|
||||
state = State.INIT;
|
||||
log.fine("Beginning mod initialization");
|
||||
|
||||
for (ModContainer mod : mods)
|
||||
{
|
||||
log.finer(String.format("Initializing %s", mod.getName()));
|
||||
mod.init();
|
||||
}
|
||||
|
||||
log.fine("Mod initialization complete");
|
||||
}
|
||||
|
||||
private void postModInit()
|
||||
{
|
||||
state = State.POSTINIT;
|
||||
log.fine("Beginning mod post-initialization");
|
||||
|
||||
for (ModContainer mod : mods)
|
||||
{
|
||||
if (mod.wantsPostInit())
|
||||
{
|
||||
log.finer(String.format("Post-initializing %s", mod.getName()));
|
||||
mod.postInit();
|
||||
}
|
||||
}
|
||||
|
||||
log.fine("Mod post-initialization complete");
|
||||
}
|
||||
|
||||
private void load()
|
||||
{
|
||||
File minecraftDir = new File(".");
|
||||
File modsDir = new File(minecraftDir, "mods");
|
||||
File configDir = new File(minecraftDir, "config");
|
||||
String canonicalModsPath;
|
||||
String canonicalConfigPath;
|
||||
|
||||
try
|
||||
{
|
||||
canonicalMinecraftDir = minecraftDir.getCanonicalFile();
|
||||
canonicalModsPath = modsDir.getCanonicalPath();
|
||||
canonicalConfigPath = configDir.getCanonicalPath();
|
||||
canonicalConfigDir = configDir.getCanonicalFile();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
log.severe(String.format("Failed to resolve mods directory mods %s", modsDir.getAbsolutePath()));
|
||||
log.throwing("fml.server.Loader", "initialize", ioe);
|
||||
throw new LoaderException(ioe);
|
||||
}
|
||||
|
||||
if (!modsDir.exists())
|
||||
{
|
||||
log.fine(String.format("No mod directory found, creating one: %s", canonicalModsPath));
|
||||
|
||||
try
|
||||
{
|
||||
modsDir.mkdir();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.throwing("fml.server.Loader", "initialize", e);
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!configDir.exists())
|
||||
{
|
||||
log.fine(String.format("No config directory found, creating one: %s", canonicalConfigPath));
|
||||
|
||||
try
|
||||
{
|
||||
configDir.mkdir();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.throwing("fml.server.Loader", "initialize", e);
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (!modsDir.isDirectory())
|
||||
{
|
||||
log.severe(String.format("Attempting to load mods from %s, which is not a directory", canonicalModsPath));
|
||||
LoaderException loaderException = new LoaderException();
|
||||
log.throwing("fml.server.Loader", "initialize", loaderException);
|
||||
throw loaderException;
|
||||
}
|
||||
|
||||
if (!configDir.isDirectory())
|
||||
{
|
||||
log.severe(String.format("Attempting to load configuration from %s, which is not a directory", canonicalConfigPath));
|
||||
LoaderException loaderException = new LoaderException();
|
||||
log.throwing("fml.server.Loader", "initialize", loaderException);
|
||||
throw loaderException;
|
||||
}
|
||||
|
||||
log.fine("Attempting to load mods contained in the minecraft jar file");
|
||||
attemptFileLoad(new File(minecraftDir, "minecraft_server.jar"));
|
||||
log.fine("Minecraft jar mods loaded successfully");
|
||||
log.info(String.format("Loading mods from %s", canonicalModsPath));
|
||||
File[] modList = modsDir.listFiles();
|
||||
// Sort the files into alphabetical order first
|
||||
Arrays.sort(modList);
|
||||
state = State.LOADING;
|
||||
|
||||
for (File modFile : modList)
|
||||
{
|
||||
if (modFile.isDirectory())
|
||||
{
|
||||
log.fine(String.format("Found a directory %s, attempting to load it", modFile.getName()));
|
||||
boolean modFound = attemptDirLoad(modFile);
|
||||
|
||||
if (modFound)
|
||||
{
|
||||
log.fine(String.format("Directory %s loaded successfully", modFile.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info(String.format("Directory %s contained no mods", modFile.getName()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Matcher matcher = zipJar.matcher(modFile.getName());
|
||||
|
||||
if (matcher.matches())
|
||||
{
|
||||
log.fine(String.format("Found a zip or jar file %s, attempting to load it", matcher.group(0)));
|
||||
boolean modFound = attemptFileLoad(modFile);
|
||||
|
||||
if (modFound)
|
||||
{
|
||||
log.fine(String.format("File %s loaded successfully", matcher.group(0)));
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info(String.format("File %s contained no mods", matcher.group(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == State.ERRORED)
|
||||
{
|
||||
log.severe("A problem has occured during mod loading, giving up now");
|
||||
throw new RuntimeException("Giving up please");
|
||||
}
|
||||
|
||||
log.info(String.format("Forge Mod Loader has loaded %d mods", mods.size()));
|
||||
}
|
||||
|
||||
private boolean attemptDirLoad(File modDir)
|
||||
{
|
||||
extendClassLoader(modDir);
|
||||
boolean foundAModClass = false;
|
||||
File[] content = modDir.listFiles(new FilenameFilter()
|
||||
{
|
||||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
return modClass.matcher(name).find();
|
||||
}
|
||||
});
|
||||
|
||||
for (File modClassFile : content)
|
||||
{
|
||||
String clazzName = modClass.matcher(modClassFile.getName()).group(2);
|
||||
log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName()));
|
||||
loadModClass(modDir, modClassFile.getName(), clazzName);
|
||||
log.fine(String.format("Successfully loaded mod class %s", modClassFile.getName()));
|
||||
foundAModClass = true;
|
||||
}
|
||||
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
private void loadModClass(File classSource, String classFileName, String clazzName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Class<?> clazz = Class.forName(clazzName, false, modClassLoader);
|
||||
|
||||
if (clazz.isAnnotationPresent(Mod.class))
|
||||
{
|
||||
// an FML mod
|
||||
mods.add(FMLModContainer.buildFor(clazz));
|
||||
}
|
||||
else if (FMLHandler.instance().isModLoaderMod(clazz))
|
||||
{
|
||||
log.fine(String.format("ModLoader BaseMod class %s found, loading", clazzName));
|
||||
ModContainer mc = FMLHandler.instance().loadBaseModMod(clazz, classSource.getCanonicalPath());
|
||||
mods.add(mc);
|
||||
log.fine(String.format("ModLoader BaseMod class %s loaded", clazzName));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unrecognized
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warning(String.format("Failed to load mod class %s in %s", classFileName, classSource.getAbsoluteFile()));
|
||||
log.throwing("fml.server.Loader", "attemptLoad", e);
|
||||
state = State.ERRORED;
|
||||
}
|
||||
}
|
||||
|
||||
private void extendClassLoader(File file)
|
||||
{
|
||||
if (modClassLoader == null)
|
||||
{
|
||||
modClassLoader = new ModClassLoader();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
modClassLoader.addFile(file);
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
throw new LoaderException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean attemptFileLoad(File modFile)
|
||||
{
|
||||
extendClassLoader(modFile);
|
||||
boolean foundAModClass = false;
|
||||
|
||||
try
|
||||
{
|
||||
ZipFile jar = new ZipFile(modFile);
|
||||
|
||||
for (ZipEntry ze : Collections.list(jar.entries()))
|
||||
{
|
||||
Matcher match = modClass.matcher(ze.getName());
|
||||
|
||||
if (match.matches())
|
||||
{
|
||||
String pkg = match.group(1).replace('/', '.');
|
||||
String clazzName = pkg + match.group(2);
|
||||
log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName()));
|
||||
loadModClass(modFile, ze.getName(), clazzName);
|
||||
log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName()));
|
||||
foundAModClass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warning(String.format("Zip file %s failed to read properly", modFile.getName()));
|
||||
log.throwing("fml.server.Loader", "attemptFileLoad", e);
|
||||
state = State.ERRORED;
|
||||
}
|
||||
|
||||
return foundAModClass;
|
||||
}
|
||||
|
||||
public static List<ModContainer> getModList()
|
||||
{
|
||||
return instance().mods;
|
||||
}
|
||||
|
||||
public void loadMods()
|
||||
{
|
||||
state = State.NOINIT;
|
||||
mods = new ArrayList<ModContainer>();
|
||||
namedMods = new HashMap<String, ModContainer>();
|
||||
load();
|
||||
preModInit();
|
||||
sortModList();
|
||||
// Make mod list immutable
|
||||
mods = Collections.unmodifiableList(mods);
|
||||
}
|
||||
|
||||
public void initializeMods()
|
||||
{
|
||||
modInit();
|
||||
postModInit();
|
||||
state = State.UP;
|
||||
log.info(String.format("Forge Mod Loader load complete, %d mods loaded", mods.size()));
|
||||
}
|
||||
|
||||
public static boolean isModLoaded(String modname)
|
||||
{
|
||||
return instance().namedMods.containsKey(modname);
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public File getConfigDir()
|
||||
{
|
||||
return canonicalConfigDir;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
/*
|
||||
* 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 cpw.mods.fml.common;
|
||||
|
||||
public class LoaderException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5675297950958861378L;
|
||||
public class LoaderException extends RuntimeException
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5675297950958861378L;
|
||||
|
||||
public LoaderException(Exception wrapped) {
|
||||
super(wrapped);
|
||||
}
|
||||
public LoaderException(Exception wrapped)
|
||||
{
|
||||
super(wrapped);
|
||||
}
|
||||
|
||||
public LoaderException() {
|
||||
}
|
||||
public LoaderException()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
@ -17,12 +17,13 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Mod {
|
||||
String name() default "";
|
||||
String version() default "";
|
||||
boolean wantsPreInit() default false;
|
||||
boolean wantsPostInit() default false;
|
||||
public @interface PreInit {}
|
||||
public @interface Init {}
|
||||
public @interface PostInit {}
|
||||
public @interface Mod
|
||||
{
|
||||
String name() default "";
|
||||
String version() default "";
|
||||
boolean wantsPreInit() default false;
|
||||
boolean wantsPostInit() default false;
|
||||
public @interface PreInit {}
|
||||
public @interface Init {}
|
||||
public @interface PostInit {}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -18,14 +18,17 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class ModClassLoader extends URLClassLoader {
|
||||
public class ModClassLoader extends URLClassLoader
|
||||
{
|
||||
|
||||
public ModClassLoader() {
|
||||
super(new URL[0],ModClassLoader.class.getClassLoader());
|
||||
}
|
||||
public ModClassLoader()
|
||||
{
|
||||
super(new URL[0], ModClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
public void addFile(File modFile) throws MalformedURLException {
|
||||
URL url=modFile.toURI().toURL();
|
||||
super.addURL(url);
|
||||
}
|
||||
public void addFile(File modFile) throws MalformedURLException
|
||||
{
|
||||
URL url = modFile.toURI().toURL();
|
||||
super.addURL(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -17,31 +17,32 @@ import java.util.List;
|
|||
|
||||
|
||||
|
||||
public interface ModContainer {
|
||||
boolean wantsPreInit();
|
||||
boolean wantsPostInit();
|
||||
void preInit();
|
||||
void init();
|
||||
void postInit();
|
||||
String getName();
|
||||
void tickStart();
|
||||
void tickEnd();
|
||||
boolean matches(Object mod);
|
||||
String getSource();
|
||||
Object getMod();
|
||||
boolean generatesWorld();
|
||||
IWorldGenerator getWorldGenerator();
|
||||
int lookupFuelValue(int itemId, int itemDamage);
|
||||
boolean wantsPickupNotification();
|
||||
IPickupNotifier getPickupNotifier();
|
||||
boolean wantsToDispense();
|
||||
IDispenseHandler getDispenseHandler();
|
||||
boolean wantsCraftingNotification();
|
||||
ICraftingHandler getCraftingHandler();
|
||||
List<String> getDependencies();
|
||||
List<String> getPreDepends();
|
||||
List<String> getPostDepends();
|
||||
boolean wantsNetworkPackets();
|
||||
INetworkHandler getNetworkHandler();
|
||||
boolean ownsNetworkChannel(String channel);
|
||||
public interface ModContainer
|
||||
{
|
||||
boolean wantsPreInit();
|
||||
boolean wantsPostInit();
|
||||
void preInit();
|
||||
void init();
|
||||
void postInit();
|
||||
String getName();
|
||||
void tickStart();
|
||||
void tickEnd();
|
||||
boolean matches(Object mod);
|
||||
String getSource();
|
||||
Object getMod();
|
||||
boolean generatesWorld();
|
||||
IWorldGenerator getWorldGenerator();
|
||||
int lookupFuelValue(int itemId, int itemDamage);
|
||||
boolean wantsPickupNotification();
|
||||
IPickupNotifier getPickupNotifier();
|
||||
boolean wantsToDispense();
|
||||
IDispenseHandler getDispenseHandler();
|
||||
boolean wantsCraftingNotification();
|
||||
ICraftingHandler getCraftingHandler();
|
||||
List<String> getDependencies();
|
||||
List<String> getPreDepends();
|
||||
List<String> getPostDepends();
|
||||
boolean wantsNetworkPackets();
|
||||
INetworkHandler getNetworkHandler();
|
||||
boolean ownsNetworkChannel(String channel);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -16,56 +16,72 @@ import java.lang.reflect.Field;
|
|||
|
||||
import cpw.mods.fml.server.FMLHandler;
|
||||
|
||||
public class ReflectionHelper {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, E instance, int fieldIndex) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
} catch (Exception e) {
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %d from %s", fieldIndex, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, E> T getPrivateValue(Class<? super E> classToAccess, E instance, String fieldName) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
} catch (Exception e) {
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, int fieldIndex, E value) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
} catch (Exception e) {
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %d from %s", fieldIndex, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
public class ReflectionHelper
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, int fieldIndex)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %d from %s", fieldIndex, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T, E> void setPrivateValue(Class<? super T> classToAccess, T instance, String fieldName, E value) {
|
||||
try {
|
||||
Field f = classToAccess.getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
} catch (Exception e) {
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T, E> T getPrivateValue(Class <? super E > classToAccess, E instance, String fieldName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = classToAccess.getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
return (T) f.get(instance);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem getting field %s from %s", fieldName, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E> void setPrivateValue(Class <? super T > classToAccess, T instance, int fieldIndex, E value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = classToAccess.getDeclaredFields()[fieldIndex];
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %d from %s", fieldIndex, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E> void setPrivateValue(Class <? super T > classToAccess, T instance, String fieldName, E value)
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = classToAccess.getDeclaredField(fieldName);
|
||||
f.setAccessible(true);
|
||||
f.set(instance, value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLHandler.getFMLLogger().severe(String.format("There was a problem setting field %s from %s", fieldName, classToAccess.getName()));
|
||||
FMLHandler.getFMLLogger().throwing("ReflectionHelper", "getPrivateValue", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -22,72 +22,95 @@ import cpw.mods.fml.common.toposort.TopologicalSort.DirectedGraph;
|
|||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ModSorter {
|
||||
private DirectedGraph<ModContainer> modGraph;
|
||||
public class ModSorter
|
||||
{
|
||||
private DirectedGraph<ModContainer> modGraph;
|
||||
|
||||
private ModContainer beforeAll = new FMLModContainer("DummyBeforeAll");
|
||||
private ModContainer afterAll = new FMLModContainer("DummyAfterAll");
|
||||
private ModContainer before = new FMLModContainer("DummyBefore");
|
||||
private ModContainer after = new FMLModContainer("DummyAfter");
|
||||
private ModContainer beforeAll = new FMLModContainer("DummyBeforeAll");
|
||||
private ModContainer afterAll = new FMLModContainer("DummyAfterAll");
|
||||
private ModContainer before = new FMLModContainer("DummyBefore");
|
||||
private ModContainer after = new FMLModContainer("DummyAfter");
|
||||
|
||||
public ModSorter(List<ModContainer> modList, Map<String, ModContainer> nameLookup) {
|
||||
buildGraph(modList, nameLookup);
|
||||
}
|
||||
|
||||
private void buildGraph(List<ModContainer> modList, Map<String, ModContainer> nameLookup) {
|
||||
modGraph = new DirectedGraph<ModContainer>();
|
||||
modGraph.addNode(beforeAll);
|
||||
modGraph.addNode(before);
|
||||
modGraph.addNode(afterAll);
|
||||
modGraph.addNode(after);
|
||||
|
||||
modGraph.addEdge(before, after);
|
||||
modGraph.addEdge(beforeAll, before);
|
||||
modGraph.addEdge(after, afterAll);
|
||||
for (ModContainer mod : modList) {
|
||||
modGraph.addNode(mod);
|
||||
public ModSorter(List<ModContainer> modList, Map<String, ModContainer> nameLookup)
|
||||
{
|
||||
buildGraph(modList, nameLookup);
|
||||
}
|
||||
for (ModContainer mod : modList) {
|
||||
boolean preDepAdded=false;
|
||||
boolean postDepAdded=false;
|
||||
for (String dep : mod.getPreDepends()) {
|
||||
preDepAdded=true;
|
||||
if (dep.equals("*")) {
|
||||
// We are "after" everything
|
||||
modGraph.addEdge(mod, afterAll);
|
||||
modGraph.addEdge(after, mod);
|
||||
postDepAdded=true;
|
||||
} else {
|
||||
modGraph.addEdge(before, mod);
|
||||
modGraph.addEdge(nameLookup.get(dep), mod);
|
||||
}
|
||||
}
|
||||
for (String dep : mod.getPostDepends()) {
|
||||
postDepAdded=true;
|
||||
if (dep.equals("*")) {
|
||||
// We are "before" everything
|
||||
modGraph.addEdge(beforeAll, mod);
|
||||
modGraph.addEdge(mod, before);
|
||||
preDepAdded=true;
|
||||
} else {
|
||||
modGraph.addEdge(mod, after);
|
||||
modGraph.addEdge(mod, nameLookup.get(dep));
|
||||
}
|
||||
}
|
||||
if (!preDepAdded) {
|
||||
modGraph.addEdge(before, mod);
|
||||
}
|
||||
if (!postDepAdded) {
|
||||
modGraph.addEdge(mod, after);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModContainer> sort() {
|
||||
List<ModContainer> sortedList=TopologicalSort.topologicalSort(modGraph);
|
||||
sortedList.removeAll(Arrays.asList(new ModContainer[] {beforeAll,before,after,afterAll}));
|
||||
return sortedList;
|
||||
}
|
||||
private void buildGraph(List<ModContainer> modList, Map<String, ModContainer> nameLookup)
|
||||
{
|
||||
modGraph = new DirectedGraph<ModContainer>();
|
||||
modGraph.addNode(beforeAll);
|
||||
modGraph.addNode(before);
|
||||
modGraph.addNode(afterAll);
|
||||
modGraph.addNode(after);
|
||||
modGraph.addEdge(before, after);
|
||||
modGraph.addEdge(beforeAll, before);
|
||||
modGraph.addEdge(after, afterAll);
|
||||
|
||||
for (ModContainer mod : modList)
|
||||
{
|
||||
modGraph.addNode(mod);
|
||||
}
|
||||
|
||||
for (ModContainer mod : modList)
|
||||
{
|
||||
boolean preDepAdded = false;
|
||||
boolean postDepAdded = false;
|
||||
|
||||
for (String dep : mod.getPreDepends())
|
||||
{
|
||||
preDepAdded = true;
|
||||
|
||||
if (dep.equals("*"))
|
||||
{
|
||||
// We are "after" everything
|
||||
modGraph.addEdge(mod, afterAll);
|
||||
modGraph.addEdge(after, mod);
|
||||
postDepAdded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
modGraph.addEdge(before, mod);
|
||||
modGraph.addEdge(nameLookup.get(dep), mod);
|
||||
}
|
||||
}
|
||||
|
||||
for (String dep : mod.getPostDepends())
|
||||
{
|
||||
postDepAdded = true;
|
||||
|
||||
if (dep.equals("*"))
|
||||
{
|
||||
// We are "before" everything
|
||||
modGraph.addEdge(beforeAll, mod);
|
||||
modGraph.addEdge(mod, before);
|
||||
preDepAdded = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
modGraph.addEdge(mod, after);
|
||||
modGraph.addEdge(mod, nameLookup.get(dep));
|
||||
}
|
||||
}
|
||||
|
||||
if (!preDepAdded)
|
||||
{
|
||||
modGraph.addEdge(before, mod);
|
||||
}
|
||||
|
||||
if (!postDepAdded)
|
||||
{
|
||||
modGraph.addEdge(mod, after);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<ModContainer> sort()
|
||||
{
|
||||
List<ModContainer> sortedList = TopologicalSort.topologicalSort(modGraph);
|
||||
sortedList.removeAll(Arrays.asList(new ModContainer[] {beforeAll, before, after, afterAll}));
|
||||
return sortedList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -25,131 +25,162 @@ import java.util.Set;
|
|||
|
||||
/**
|
||||
* Topological sort for mod loading
|
||||
*
|
||||
*
|
||||
* Based on a variety of sources, including http://keithschwarz.com/interesting/code/?dir=topological-sort
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class TopologicalSort {
|
||||
public static class DirectedGraph<T> implements Iterable<T> {
|
||||
private final Map<T, Set<T>> graph=new HashMap<T,Set<T>>();
|
||||
|
||||
public boolean addNode(T node) {
|
||||
// Ignore nodes already added
|
||||
if (graph.containsKey(node)) {
|
||||
return false;
|
||||
}
|
||||
graph.put(node, new HashSet<T>());
|
||||
return true;
|
||||
public class TopologicalSort
|
||||
{
|
||||
public static class DirectedGraph<T> implements Iterable<T>
|
||||
{
|
||||
private final Map<T, Set<T>> graph = new HashMap<T, Set<T>>();
|
||||
|
||||
public boolean addNode(T node)
|
||||
{
|
||||
// Ignore nodes already added
|
||||
if (graph.containsKey(node))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
graph.put(node, new HashSet<T>());
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addEdge(T from, T to)
|
||||
{
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to)))
|
||||
{
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
|
||||
graph.get(from).add(to);
|
||||
}
|
||||
|
||||
public void removeEdge(T from, T to)
|
||||
{
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to)))
|
||||
{
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
|
||||
graph.get(from).remove(to);
|
||||
}
|
||||
|
||||
public boolean edgeExists(T from, T to)
|
||||
{
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to)))
|
||||
{
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
|
||||
return graph.get(from).contains(to);
|
||||
}
|
||||
|
||||
public Set<T> edgesFrom(T from)
|
||||
{
|
||||
if (!graph.containsKey(from))
|
||||
{
|
||||
throw new NoSuchElementException("Missing node from graph");
|
||||
}
|
||||
|
||||
return Collections.unmodifiableSet(graph.get(from));
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return graph.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return graph.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return graph.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return graph.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public void addEdge(T from, T to) {
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to))) {
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
graph.get(from).add(to);
|
||||
|
||||
/**
|
||||
* Sort the input graph into a topologically sorted list
|
||||
*
|
||||
* Uses the reverse depth first search as outlined in ...
|
||||
* @param graph
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> topologicalSort(DirectedGraph<T> graph)
|
||||
{
|
||||
DirectedGraph<T> rGraph = reverse(graph);
|
||||
List<T> sortedResult = new ArrayList<T>();
|
||||
Set<T> visitedNodes = new HashSet<T>();
|
||||
// A list of "fully explored" nodes. Leftovers in here indicate cycles in the graph
|
||||
Set<T> expandedNodes = new HashSet<T>();
|
||||
|
||||
for (T node : rGraph)
|
||||
{
|
||||
explore(node, rGraph, sortedResult, visitedNodes, expandedNodes);
|
||||
}
|
||||
|
||||
return sortedResult;
|
||||
}
|
||||
|
||||
public void removeEdge(T from, T to) {
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to))) {
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
graph.get(from).remove(to);
|
||||
|
||||
public static <T> DirectedGraph<T> reverse(DirectedGraph<T> graph)
|
||||
{
|
||||
DirectedGraph<T> result = new DirectedGraph<T>();
|
||||
|
||||
for (T node : graph)
|
||||
{
|
||||
result.addNode(node);
|
||||
}
|
||||
|
||||
for (T from : graph)
|
||||
{
|
||||
for (T to : graph.edgesFrom(from))
|
||||
{
|
||||
result.addEdge(to, from);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean edgeExists(T from, T to) {
|
||||
if (!(graph.containsKey(from) && graph.containsKey(to))) {
|
||||
throw new NoSuchElementException("Missing nodes from graph");
|
||||
}
|
||||
return graph.get(from).contains(to);
|
||||
|
||||
public static <T> void explore(T node, DirectedGraph<T> graph, List<T> sortedResult, Set<T> visitedNodes, Set<T> expandedNodes)
|
||||
{
|
||||
// Have we been here before?
|
||||
if (visitedNodes.contains(node))
|
||||
{
|
||||
// And have completed this node before
|
||||
if (expandedNodes.contains(node))
|
||||
{
|
||||
// Then we're fine
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.printf("%s: %s\n%s\n%s\n", node, sortedResult, visitedNodes, expandedNodes);
|
||||
throw new IllegalArgumentException("There was a cycle detected in the input graph, sorting is not possible");
|
||||
}
|
||||
|
||||
// Visit this node
|
||||
visitedNodes.add(node);
|
||||
|
||||
// Recursively explore inbound edges
|
||||
for (T inbound : graph.edgesFrom(node))
|
||||
{
|
||||
explore(inbound, graph, sortedResult, visitedNodes, expandedNodes);
|
||||
}
|
||||
|
||||
// Add ourselves now
|
||||
sortedResult.add(node);
|
||||
// And mark ourselves as explored
|
||||
expandedNodes.add(node);
|
||||
}
|
||||
|
||||
public Set<T> edgesFrom(T from) {
|
||||
if (!graph.containsKey(from)) {
|
||||
throw new NoSuchElementException("Missing node from graph");
|
||||
}
|
||||
return Collections.unmodifiableSet(graph.get(from));
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return graph.keySet().iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return graph.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return graph.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return graph.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the input graph into a topologically sorted list
|
||||
*
|
||||
* Uses the reverse depth first search as outlined in ...
|
||||
* @param graph
|
||||
* @return
|
||||
*/
|
||||
public static <T> List<T> topologicalSort(DirectedGraph<T> graph) {
|
||||
DirectedGraph<T> rGraph=reverse(graph);
|
||||
|
||||
List<T> sortedResult=new ArrayList<T>();
|
||||
Set<T> visitedNodes=new HashSet<T>();
|
||||
|
||||
// A list of "fully explored" nodes. Leftovers in here indicate cycles in the graph
|
||||
Set<T> expandedNodes=new HashSet<T>();
|
||||
|
||||
for (T node : rGraph) {
|
||||
explore(node, rGraph, sortedResult, visitedNodes, expandedNodes);
|
||||
}
|
||||
|
||||
return sortedResult;
|
||||
}
|
||||
|
||||
public static <T> DirectedGraph<T> reverse(DirectedGraph<T> graph) {
|
||||
DirectedGraph<T> result=new DirectedGraph<T>();
|
||||
for (T node : graph) {
|
||||
result.addNode(node);
|
||||
}
|
||||
for (T from : graph) {
|
||||
for (T to : graph.edgesFrom(from)) {
|
||||
result.addEdge(to, from);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T> void explore(T node, DirectedGraph<T> graph, List<T> sortedResult, Set<T> visitedNodes, Set<T> expandedNodes) {
|
||||
// Have we been here before?
|
||||
if (visitedNodes.contains(node)) {
|
||||
// And have completed this node before
|
||||
if (expandedNodes.contains(node)) {
|
||||
// Then we're fine
|
||||
return;
|
||||
}
|
||||
System.out.printf("%s: %s\n%s\n%s\n",node,sortedResult,visitedNodes,expandedNodes);
|
||||
throw new IllegalArgumentException("There was a cycle detected in the input graph, sorting is not possible");
|
||||
}
|
||||
|
||||
// Visit this node
|
||||
visitedNodes.add(node);
|
||||
|
||||
// Recursively explore inbound edges
|
||||
for (T inbound : graph.edgesFrom(node)) {
|
||||
explore(inbound, graph, sortedResult, visitedNodes, expandedNodes);
|
||||
}
|
||||
|
||||
// Add ourselves now
|
||||
sortedResult.add(node);
|
||||
|
||||
// And mark ourselves as explored
|
||||
expandedNodes.add(node);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -16,97 +16,128 @@ package net.minecraft.src;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommonRegistry {
|
||||
public static void addRecipe(ItemStack output, Object... params) {
|
||||
CraftingManager.func_20151_a().func_20153_a(output, params);
|
||||
}
|
||||
|
||||
public static void addShapelessRecipe(ItemStack output, Object... params) {
|
||||
CraftingManager.func_20151_a().func_21146_b(output, params);
|
||||
}
|
||||
|
||||
public static void addSmelting(int input, ItemStack output) {
|
||||
FurnaceRecipes.func_21162_a().func_21160_a(input, output);
|
||||
}
|
||||
|
||||
public static void registerBlock(Block block) {
|
||||
registerBlock(block,ItemBlock.class);
|
||||
}
|
||||
|
||||
public static void registerBlock(Block block, Class<? extends ItemBlock> itemclass) {
|
||||
try {
|
||||
assert block!=null : "registerBlock: block cannot be null";
|
||||
assert itemclass!=null : "registerBlock: itemclass cannot be null";
|
||||
int blockItemId=block.field_573_bc-256;
|
||||
itemclass.getConstructor(int.class).newInstance(blockItemId);
|
||||
} catch (Exception e) {
|
||||
//HMMM
|
||||
public class CommonRegistry
|
||||
{
|
||||
public static void addRecipe(ItemStack output, Object... params)
|
||||
{
|
||||
CraftingManager.func_20151_a().func_20153_a(output, params);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerEntityID(Class<? extends Entity> entityClass, String entityName, int id) {
|
||||
EntityList.addNewEntityListMapping(entityClass, entityName, id);
|
||||
}
|
||||
public static void addShapelessRecipe(ItemStack output, Object... params)
|
||||
{
|
||||
CraftingManager.func_20151_a().func_21146_b(output, params);
|
||||
}
|
||||
|
||||
public static void registerEntityID(Class<? extends Entity> entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) {
|
||||
EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
|
||||
}
|
||||
public static void addSmelting(int input, ItemStack output)
|
||||
{
|
||||
FurnaceRecipes.func_21162_a().func_21160_a(input, output);
|
||||
}
|
||||
|
||||
public static void registerTileEntity(Class<? extends TileEntity> tileEntityClass, String id) {
|
||||
TileEntity.addNewTileEntityMapping(tileEntityClass, id);
|
||||
}
|
||||
public static void registerBlock(Block block)
|
||||
{
|
||||
registerBlock(block, ItemBlock.class);
|
||||
}
|
||||
|
||||
public static void addBiome(BiomeGenBase biome) {
|
||||
//NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already.
|
||||
}
|
||||
|
||||
public static void addSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) {
|
||||
for (BiomeGenBase biome : biomes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SpawnListEntry> spawns=biome.func_25055_a(typeOfCreature);
|
||||
for (SpawnListEntry entry : spawns) {
|
||||
//Adjusting an existing spawn entry
|
||||
if (entry.field_25145_a==entityClass) {
|
||||
entry.field_35483_d=weightedProb;
|
||||
entry.field_35484_b=min;
|
||||
entry.field_35485_c=max;
|
||||
break;
|
||||
public static void registerBlock(Block block, Class <? extends ItemBlock > itemclass)
|
||||
{
|
||||
try
|
||||
{
|
||||
assert block != null : "registerBlock: block cannot be null";
|
||||
assert itemclass != null : "registerBlock: itemclass cannot be null";
|
||||
int blockItemId = block.field_573_bc - 256;
|
||||
itemclass.getConstructor(int.class).newInstance(blockItemId);
|
||||
}
|
||||
}
|
||||
spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) {
|
||||
Class<? extends Entity> entityClazz=EntityList.getEntityToClassMapping().get(entityName);
|
||||
if (EntityLiving.class.isAssignableFrom(entityClazz)) {
|
||||
addSpawn((Class<? extends EntityLiving>) entityClazz,weightedProb,min,max,spawnList,biomes);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeBiome(BiomeGenBase biome) {
|
||||
// NOOP because broken
|
||||
}
|
||||
|
||||
public static void removeSpawn(Class<? extends EntityLiving> entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) {
|
||||
for (BiomeGenBase biome : biomes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SpawnListEntry> spawns=biome.func_25055_a(typeOfCreature);
|
||||
for (SpawnListEntry entry : Collections.unmodifiableList(spawns)) {
|
||||
if (entry.field_25145_a==entityClass) {
|
||||
spawns.remove(entry);
|
||||
catch (Exception e)
|
||||
{
|
||||
//HMMM
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) {
|
||||
Class<? extends Entity> entityClazz=EntityList.getEntityToClassMapping().get(entityName);
|
||||
if (EntityLiving.class.isAssignableFrom(entityClazz)) {
|
||||
removeSpawn((Class<? extends EntityLiving>) entityClazz,spawnList,biomes);
|
||||
public static void registerEntityID(Class <? extends Entity > entityClass, String entityName, int id)
|
||||
{
|
||||
EntityList.addNewEntityListMapping(entityClass, entityName, id);
|
||||
}
|
||||
|
||||
public static void registerEntityID(Class <? extends Entity > entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)
|
||||
{
|
||||
EntityList.addNewEntityListMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
|
||||
}
|
||||
|
||||
public static void registerTileEntity(Class <? extends TileEntity > tileEntityClass, String id)
|
||||
{
|
||||
TileEntity.addNewTileEntityMapping(tileEntityClass, id);
|
||||
}
|
||||
|
||||
public static void addBiome(BiomeGenBase biome)
|
||||
{
|
||||
//NOOP because the implementation idea is broken. Creating a BiomeGenBase adds the biome already.
|
||||
}
|
||||
|
||||
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
|
||||
{
|
||||
for (BiomeGenBase biome : biomes)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SpawnListEntry> spawns = biome.func_25055_a(typeOfCreature);
|
||||
|
||||
for (SpawnListEntry entry : spawns)
|
||||
{
|
||||
//Adjusting an existing spawn entry
|
||||
if (entry.field_25145_a == entityClass)
|
||||
{
|
||||
entry.field_35483_d = weightedProb;
|
||||
entry.field_35484_b = min;
|
||||
entry.field_35485_c = max;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes)
|
||||
{
|
||||
Class <? extends Entity > entityClazz = EntityList.getEntityToClassMapping().get(entityName);
|
||||
|
||||
if (EntityLiving.class.isAssignableFrom(entityClazz))
|
||||
{
|
||||
addSpawn((Class <? extends EntityLiving >) entityClazz, weightedProb, min, max, spawnList, biomes);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeBiome(BiomeGenBase biome)
|
||||
{
|
||||
// NOOP because broken
|
||||
}
|
||||
|
||||
public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
|
||||
{
|
||||
for (BiomeGenBase biome : biomes)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
List<SpawnListEntry> spawns = biome.func_25055_a(typeOfCreature);
|
||||
|
||||
for (SpawnListEntry entry : Collections.unmodifiableList(spawns))
|
||||
{
|
||||
if (entry.field_25145_a == entityClass)
|
||||
{
|
||||
spawns.remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes)
|
||||
{
|
||||
Class <? extends Entity > entityClazz = EntityList.getEntityToClassMapping().get(entityName);
|
||||
|
||||
if (EntityLiving.class.isAssignableFrom(entityClazz))
|
||||
{
|
||||
removeSpawn((Class <? extends EntityLiving >) entityClazz, spawnList, biomes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue