mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
Moved MLMP compatibility functions to ModCompatibilityClient, and fixed issue where no vehicles would be spawned.
This commit is contained in:
1 parent
796d4fea70
commit
4bdba7400b
3 files changed
+128
-86
No files matched your search
@@ -322,78 +322,6 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to try and invoke ModLoaderMp's NetClientHandler.handleVehicleSpawn modifications
|
||||
* if ModLoaderMp is install along side Forge.
|
||||
*/
|
||||
public static Object tryMLMPVehicleSpawn(int type, World world, double x, double y, double z, Entity thrower) throws Exception
|
||||
{
|
||||
Class mlmp = getClass("ModLoaderMp");
|
||||
if (mlmp == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Object entry = mlmp.getDeclaredMethod("handleNetClientHandlerEntities", int.class).invoke(null, type);
|
||||
if (entry == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Class entityClass = (Class)entry.getClass().getDeclaredField("entityClass").get(entry);
|
||||
Object ret = (Entity)entityClass.getConstructor(World.class, Double.TYPE, Double.TYPE, Double.TYPE).newInstance(world, x, y, z);
|
||||
|
||||
if (entry.getClass().getDeclaredField("entityHasOwner").getBoolean(entry))
|
||||
{
|
||||
Field owner = entityClass.getField("owner");
|
||||
|
||||
if (!Entity.class.isAssignableFrom(owner.getType()))
|
||||
{
|
||||
throw new Exception(String.format("Entity\'s owner field must be of type Entity, but it is of type %s.", owner.getType()));
|
||||
}
|
||||
|
||||
if (thrower == null)
|
||||
{
|
||||
System.out.println("Received spawn packet for entity with owner, but owner was not found.");
|
||||
ModLoader.getLogger().fine("Received spawn packet for entity with owner, but owner was not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!owner.getType().isAssignableFrom(thrower.getClass()))
|
||||
{
|
||||
throw new Exception(String.format("Tried to assign an entity of type %s to entity owner, which is of type %s.", thrower.getClass(), owner.getType()));
|
||||
}
|
||||
|
||||
owner.set(ret, thrower);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* helper function to try and call ModLoaderMp's handleGUI function
|
||||
* if ModLoaderMp is installed client side along with Forge.
|
||||
*
|
||||
* @param pkt The open window packet
|
||||
*/
|
||||
public static void tryMLMPOpenWindow(Packet100OpenWindow pkt)
|
||||
{
|
||||
Class mlmp = getClass("ModLoaderMp");
|
||||
if (mlmp == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mlmp.getDeclaredMethod("handleGUI", Packet100OpenWindow.class).invoke(null, pkt);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedList<ISoundHandler> soundHandlers = new LinkedList<ISoundHandler>();
|
||||
public static void onSetupAudio(SoundManager soundManager)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.minecraft.src.forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import paulscode.sound.SoundSystemConfig;
|
||||
|
||||
@@ -174,4 +175,116 @@ public class ModCompatibilityClient
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************
|
||||
* SDK's ModLoaderMP
|
||||
* http://www.minecraftforum.net/topic/86765-
|
||||
*
|
||||
* ModLoaderMP was supposed to be a reliable server side version of ModLoader, however it has
|
||||
* gotten the reputation of being really slow to update. Never having bugfixes, breaking compatibility
|
||||
* with the client side ModLoader.
|
||||
*
|
||||
* So we have replaced it with our own system called FML (Forge ModLoader)
|
||||
* it is a stand alone mod, that Forge relies on, and that is open source/community driven.
|
||||
* https://github.com/cpw/FML
|
||||
*
|
||||
* However, for compatibilities sake, we provide the ModLoaderMP's hooks so that the end user
|
||||
* does not need to make a choice between the two on the client side.
|
||||
**/
|
||||
private static int isMLMPInstalled = -1;
|
||||
|
||||
/**
|
||||
* Determine if ModLoaderMP is installed by checking for the existence of the BaseModMp class.
|
||||
* @return True if BaseModMp was installed (indicating the existance of MLMP)
|
||||
*/
|
||||
public static boolean isMLMPInstalled()
|
||||
{
|
||||
if (isMLMPInstalled == -1)
|
||||
{
|
||||
isMLMPInstalled = (getClass("ModLoaderMp") != null ? 1 : 0);
|
||||
}
|
||||
return isMLMPInstalled == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to spawn a vehicle using ModLoaderMP's vehicle spawn registry, if MLMP is not installed
|
||||
* it returns the passed in currentEntity
|
||||
*
|
||||
* @param type The Type ID of the vehicle
|
||||
* @param world The current world
|
||||
* @param x The spawn X position
|
||||
* @param y The spawn Y position
|
||||
* @param z The spawn Z position
|
||||
* @param thrower The entity that spawned the vehicle {possibly null}
|
||||
* @param currentEntity The current value to return if MLMP is not installed
|
||||
* @return The new spawned entity
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Object mlmpVehicleSpawn(int type, World world, double x, double y, double z, Entity thrower, Object currentEntity) throws Exception
|
||||
{
|
||||
Class mlmp = getClass("ModLoaderMp");
|
||||
if (!isMLMPInstalled() || mlmp == null)
|
||||
{
|
||||
return currentEntity;
|
||||
}
|
||||
|
||||
Object entry = mlmp.getDeclaredMethod("handleNetClientHandlerEntities", int.class).invoke(null, type);
|
||||
if (entry == null)
|
||||
{
|
||||
return currentEntity;
|
||||
}
|
||||
|
||||
Class entityClass = (Class)entry.getClass().getDeclaredField("entityClass").get(entry);
|
||||
Object ret = (Entity)entityClass.getConstructor(World.class, Double.TYPE, Double.TYPE, Double.TYPE).newInstance(world, x, y, z);
|
||||
|
||||
if (entry.getClass().getDeclaredField("entityHasOwner").getBoolean(entry))
|
||||
{
|
||||
Field owner = entityClass.getField("owner");
|
||||
|
||||
if (!Entity.class.isAssignableFrom(owner.getType()))
|
||||
{
|
||||
throw new Exception(String.format("Entity\'s owner field must be of type Entity, but it is of type %s.", owner.getType()));
|
||||
}
|
||||
|
||||
if (thrower == null)
|
||||
{
|
||||
System.out.println("Received spawn packet for entity with owner, but owner was not found.");
|
||||
ModLoader.getLogger().fine("Received spawn packet for entity with owner, but owner was not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!owner.getType().isAssignableFrom(thrower.getClass()))
|
||||
{
|
||||
throw new Exception(String.format("Tried to assign an entity of type %s to entity owner, which is of type %s.", thrower.getClass(), owner.getType()));
|
||||
}
|
||||
|
||||
owner.set(ret, thrower);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to invoke ModLoaderMp.handleGUI if ModLoaderMP is installed.
|
||||
* If not, it does nothing
|
||||
*
|
||||
* @param pkt The open window packet
|
||||
*/
|
||||
public static void mlmpOpenWindow(Packet100OpenWindow pkt)
|
||||
{
|
||||
Class mlmp = getClass("ModLoaderMp");
|
||||
if (!isMLMPInstalled() || mlmp == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mlmp.getDeclaredMethod("handleGUI", Packet100OpenWindow.class).invoke(null, pkt);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user