mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 20:52:34 +00:00
GUIs working in FML for ML mods
This commit is contained in:
1 parent
52483ee6bd
commit
3a8b047e3c
10 files changed
+87
-19
No files matched your search
@@ -85,7 +85,4 @@ public interface BaseModProxy
|
||||
public abstract void receiveChatPacket(String text);
|
||||
|
||||
public abstract void onItemPickup(EntityPlayer player, ItemStack item);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract GuiScreen getContainerGUI(EntityPlayer player, int containerID, int x, int y, int z);
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package cpw.mods.fml.common.modloader;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
|
||||
public interface IModLoaderSidedHelper
|
||||
{
|
||||
|
||||
void finishModLoading(ModLoaderModContainer mc);
|
||||
|
||||
Object getClientGui(BaseModProxy mod, EntityPlayer player, int iD, int x, int y, int z);
|
||||
|
||||
}
|
||||
@@ -21,13 +21,16 @@ public class ModLoaderGuiHelper implements IGuiHandler
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
System.out.printf("returning container %s, %d for server side\n", container, id);
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||
{
|
||||
return mod.getContainerGUI(player, ID, x, y, z);
|
||||
Object o = ModLoaderHelper.getClientSideGui(mod, player, ID, x, y, z);
|
||||
System.out.printf("fetching gui %s %d for client side\n", o, id);
|
||||
return o;
|
||||
}
|
||||
|
||||
public void injectContainer(Container container)
|
||||
|
||||
@@ -127,12 +127,23 @@ public class ModLoaderHelper
|
||||
{
|
||||
ModLoaderGuiHelper handler = new ModLoaderGuiHelper(mod, id);
|
||||
guiHelpers.put(id, handler);
|
||||
NetworkRegistry.instance().registerGuiHandler(Loader.instance().activeModContainer(), handler);
|
||||
NetworkRegistry.instance().registerGuiHandler(mod, handler);
|
||||
}
|
||||
|
||||
public static void openGui(int id, EntityPlayer player, Container container, int x, int y, int z)
|
||||
{
|
||||
guiHelpers.get(id).injectContainer(container);
|
||||
player.openGui(guiHelpers.get(id).getMod(), id, player.field_70170_p, x, y, z);
|
||||
ModLoaderGuiHelper helper = guiHelpers.get(id);
|
||||
helper.injectContainer(container);
|
||||
System.out.printf("Opening GUI %d %s at %d %d %d\n", id, container, x,y,z);
|
||||
player.openGui(helper.getMod(), id, player.field_70170_p, x, y, z);
|
||||
}
|
||||
|
||||
public static Object getClientSideGui(BaseModProxy mod, EntityPlayer player, int ID, int x, int y, int z)
|
||||
{
|
||||
if (sidedHelper != null)
|
||||
{
|
||||
return sidedHelper.getClientGui(mod, player, ID, x, y, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -142,6 +142,7 @@ public class ModLoaderModContainer implements ModContainer
|
||||
try
|
||||
{
|
||||
mlPropFields.add(new ModProperty(modClazz.getDeclaredField(dat.getObjectName()), dat.getAnnotationInfo()));
|
||||
FMLLog.finest("Found an MLProp field %s in %s", dat.getObjectName(), modClazzName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -484,6 +485,11 @@ public class ModLoaderModContainer implements ModContainer
|
||||
configureMod(modClazz, event.getASMHarvestedData());
|
||||
isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, modClazz, event.getASMHarvestedData());
|
||||
mod = (BaseModProxy)modClazz.newInstance();
|
||||
if (!isNetworkMod)
|
||||
{
|
||||
FMLLog.fine("Injecting dummy network mod handler for BaseMod %s", getModId());
|
||||
FMLNetworkHandler.instance().registerNetworkMod(new ModLoaderNetworkHandler(this, mod));
|
||||
}
|
||||
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package cpw.mods.fml.common.modloader;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkModHandler;
|
||||
|
||||
public class ModLoaderNetworkHandler extends NetworkModHandler
|
||||
{
|
||||
|
||||
private BaseModProxy baseMod;
|
||||
public ModLoaderNetworkHandler(ModLoaderModContainer mlmc, BaseModProxy mod)
|
||||
{
|
||||
super(mlmc, null);
|
||||
this.baseMod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresClientSide()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresServerSide()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptVersion(String version)
|
||||
{
|
||||
return baseMod.getVersion().equals(version);
|
||||
}
|
||||
@Override
|
||||
public boolean isNetworkMod()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -29,12 +29,12 @@ public class ModProperty
|
||||
private String name;
|
||||
private Field field;
|
||||
|
||||
public ModProperty(Field f, String info, double min, double max, String name)
|
||||
public ModProperty(Field f, String info, Double min, Double max, String name)
|
||||
{
|
||||
this.field = f;
|
||||
this.info = info;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.min = min != null ? min : Double.MIN_VALUE;
|
||||
this.max = max != null ? max : Double.MAX_VALUE;
|
||||
this.name = name;
|
||||
}
|
||||
public ModProperty(Field field, Map<String, Object> annotationInfo)
|
||||
|
||||
Reference in new issue
Block a user