GUIs working in FML for ML mods
This commit is contained in:
parent
bb98ae9e28
commit
b8a30cec94
10 changed files with 87 additions and 19 deletions
|
@ -8,6 +8,8 @@ import java.util.Map.Entry;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.src.BaseMod;
|
import net.minecraft.src.BaseMod;
|
||||||
import net.minecraft.src.Entity;
|
import net.minecraft.src.Entity;
|
||||||
|
import net.minecraft.src.EntityClientPlayerMP;
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
import net.minecraft.src.KeyBinding;
|
import net.minecraft.src.KeyBinding;
|
||||||
import net.minecraft.src.Render;
|
import net.minecraft.src.Render;
|
||||||
|
|
||||||
|
@ -92,4 +94,11 @@ public class ModLoaderClientHelper implements IModLoaderSidedHelper
|
||||||
handler.addKeyBinding(keyHandler, allowRepeat);
|
handler.addKeyBinding(keyHandler, allowRepeat);
|
||||||
KeyBindingRegistry.registerKeyBinding(handler);
|
KeyBindingRegistry.registerKeyBinding(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getClientGui(BaseModProxy mod, EntityPlayer player, int ID, int x, int y, int z)
|
||||||
|
{
|
||||||
|
return ((net.minecraft.src.BaseMod)mod).getContainerGUI((EntityClientPlayerMP) player, ID, x, y, z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,8 +234,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SideOnly(CLIENT)
|
@SideOnly(CLIENT)
|
||||||
@Override
|
public GuiContainer getContainerGUI(EntityClientPlayerMP player, int containerID, int x, int y, int z)
|
||||||
public GuiScreen getContainerGUI(EntityPlayer player, int containerID, int x, int y, int z)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ import cpw.mods.fml.common.FMLLog;
|
||||||
import cpw.mods.fml.common.Loader;
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||||
import cpw.mods.fml.common.asm.SideOnly;
|
import cpw.mods.fml.common.asm.SideOnly;
|
||||||
import cpw.mods.fml.common.modloader.BaseModProxy;
|
|
||||||
import cpw.mods.fml.common.modloader.ModLoaderHelper;
|
import cpw.mods.fml.common.modloader.ModLoaderHelper;
|
||||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
@ -573,7 +572,7 @@ public class ModLoader
|
||||||
GameRegistry.registerBlock(block, itemclass);
|
GameRegistry.registerBlock(block, itemclass);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerContainerID(BaseModProxy mod, int id)
|
public static void registerContainerID(BaseMod mod, int id)
|
||||||
{
|
{
|
||||||
ModLoaderHelper.buildGuiHelper(mod, id);
|
ModLoaderHelper.buildGuiHelper(mod, id);
|
||||||
}
|
}
|
||||||
|
@ -604,7 +603,7 @@ public class ModLoader
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(CLIENT)
|
@SideOnly(CLIENT)
|
||||||
public static void registerKey(BaseModProxy mod, KeyBinding keyHandler, boolean allowRepeat)
|
public static void registerKey(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat)
|
||||||
{
|
{
|
||||||
ModLoaderClientHelper.registerKeyBinding(mod, keyHandler, allowRepeat);
|
ModLoaderClientHelper.registerKeyBinding(mod, keyHandler, allowRepeat);
|
||||||
}
|
}
|
||||||
|
@ -616,7 +615,7 @@ public class ModLoader
|
||||||
* @param mod
|
* @param mod
|
||||||
* @param channel
|
* @param channel
|
||||||
*/
|
*/
|
||||||
public static void registerPacketChannel(BaseModProxy mod, String channel)
|
public static void registerPacketChannel(BaseMod mod, String channel)
|
||||||
{
|
{
|
||||||
NetworkRegistry.instance().registerChannel(ModLoaderHelper.buildPacketHandlerFor(mod), channel);
|
NetworkRegistry.instance().registerChannel(ModLoaderHelper.buildPacketHandlerFor(mod), channel);
|
||||||
}
|
}
|
||||||
|
@ -751,7 +750,7 @@ public class ModLoader
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serverOpenWindow(EntityPlayer player, Container container, int ID, int x, int y, int z)
|
public static void serverOpenWindow(EntityPlayerMP player, Container container, int ID, int x, int y, int z)
|
||||||
{
|
{
|
||||||
ModLoaderHelper.openGui(ID, player, container, x, y, z);
|
ModLoaderHelper.openGui(ID, player, container, x, y, z);
|
||||||
}
|
}
|
||||||
|
@ -763,13 +762,13 @@ public class ModLoader
|
||||||
* @param enable indicates whether you want to recieve them or not
|
* @param enable indicates whether you want to recieve them or not
|
||||||
* @param useClock don't receive render subticks, just world ticks
|
* @param useClock don't receive render subticks, just world ticks
|
||||||
*/
|
*/
|
||||||
public static void setInGameHook(BaseModProxy mod, boolean enable, boolean useClock)
|
public static void setInGameHook(BaseMod mod, boolean enable, boolean useClock)
|
||||||
{
|
{
|
||||||
ModLoaderHelper.updateStandardTicks(mod, enable, useClock);
|
ModLoaderHelper.updateStandardTicks(mod, enable, useClock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setInGUIHook(BaseModProxy mod, boolean enable, boolean useClock)
|
public static void setInGUIHook(BaseMod mod, boolean enable, boolean useClock)
|
||||||
{
|
{
|
||||||
ModLoaderHelper.updateGUITicks(mod, enable, useClock);
|
ModLoaderHelper.updateGUITicks(mod, enable, useClock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,4 @@ public interface BaseModProxy
|
||||||
public abstract void receiveChatPacket(String text);
|
public abstract void receiveChatPacket(String text);
|
||||||
|
|
||||||
public abstract void onItemPickup(EntityPlayer player, ItemStack item);
|
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;
|
package cpw.mods.fml.common.modloader;
|
||||||
|
|
||||||
|
import net.minecraft.src.EntityPlayer;
|
||||||
|
|
||||||
public interface IModLoaderSidedHelper
|
public interface IModLoaderSidedHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
void finishModLoading(ModLoaderModContainer mc);
|
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
|
@Override
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
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;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
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)
|
public void injectContainer(Container container)
|
||||||
|
|
|
@ -127,12 +127,23 @@ public class ModLoaderHelper
|
||||||
{
|
{
|
||||||
ModLoaderGuiHelper handler = new ModLoaderGuiHelper(mod, id);
|
ModLoaderGuiHelper handler = new ModLoaderGuiHelper(mod, id);
|
||||||
guiHelpers.put(id, handler);
|
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)
|
public static void openGui(int id, EntityPlayer player, Container container, int x, int y, int z)
|
||||||
{
|
{
|
||||||
guiHelpers.get(id).injectContainer(container);
|
ModLoaderGuiHelper helper = guiHelpers.get(id);
|
||||||
player.openGui(guiHelpers.get(id).getMod(), id, player.field_70170_p, x, y, z);
|
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
|
try
|
||||||
{
|
{
|
||||||
mlPropFields.add(new ModProperty(modClazz.getDeclaredField(dat.getObjectName()), dat.getAnnotationInfo()));
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -484,6 +485,11 @@ public class ModLoaderModContainer implements ModContainer
|
||||||
configureMod(modClazz, event.getASMHarvestedData());
|
configureMod(modClazz, event.getASMHarvestedData());
|
||||||
isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, modClazz, event.getASMHarvestedData());
|
isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, modClazz, event.getASMHarvestedData());
|
||||||
mod = (BaseModProxy)modClazz.newInstance();
|
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());
|
ProxyInjector.inject(this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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 String name;
|
||||||
private Field field;
|
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.field = f;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.min = min;
|
this.min = min != null ? min : Double.MIN_VALUE;
|
||||||
this.max = max;
|
this.max = max != null ? max : Double.MAX_VALUE;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
public ModProperty(Field field, Map<String, Object> annotationInfo)
|
public ModProperty(Field field, Map<String, Object> annotationInfo)
|
||||||
|
|
Loading…
Reference in a new issue