mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
--- ../src_base/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
|
||||
+++ ../src_work/minecraft/net/minecraft/src/NetClientHandler.java 0000-00-00 00:00:00.000000000 -0000
|
||||
@@ -14,7 +14,14 @@
|
||||
@@ -14,7 +14,15 @@
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
@@ -10,12 +10,13 @@
|
||||
+import net.minecraft.src.forge.ForgeHooks;
|
||||
+import net.minecraft.src.forge.ForgeHooksClient;
|
||||
+import net.minecraft.src.forge.MessageManager;
|
||||
+import net.minecraft.src.forge.ModCompatibilityClient;
|
||||
+import net.minecraft.src.forge.packets.ForgePacket;
|
||||
+import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class NetClientHandler extends NetHandler
|
||||
{
|
||||
@@ -46,6 +53,8 @@
|
||||
@@ -46,6 +54,8 @@
|
||||
this.mc = par1Minecraft;
|
||||
Socket var4 = new Socket(InetAddress.getByName(par2Str), par3);
|
||||
this.netManager = new NetworkManager(var4, "Client", this);
|
||||
@@ -24,7 +25,7 @@
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,6 +82,30 @@
|
||||
@@ -73,6 +83,30 @@
|
||||
this.mc.thePlayer.entityId = par1Packet1Login.protocolVersion;
|
||||
this.currentServerMaxPlayers = par1Packet1Login.maxPlayers;
|
||||
((PlayerControllerMP)this.mc.playerController).setCreative(par1Packet1Login.serverMode == 1);
|
||||
@@ -55,16 +56,16 @@
|
||||
ModLoader.serverConnect(this, par1Packet1Login);
|
||||
}
|
||||
|
||||
@@ -178,6 +211,19 @@
|
||||
@@ -178,6 +212,19 @@
|
||||
{
|
||||
var8 = new EntityFallingSand(this.worldClient, var2, var4, var6, Block.dragonEgg.blockID);
|
||||
}
|
||||
+
|
||||
+ try
|
||||
+ {
|
||||
+ var8 = ForgeHooksClient.tryMLMPVehicleSpawn(par1Packet23VehicleSpawn.type,
|
||||
+ var8 = ModCompatibilityClient.mlmpVehicleSpawn(par1Packet23VehicleSpawn.type,
|
||||
+ worldClient, var2, var4, var6,
|
||||
+ getEntityByID(par1Packet23VehicleSpawn.throwerEntityId));
|
||||
+ getEntityByID(par1Packet23VehicleSpawn.throwerEntityId), var8);
|
||||
+ }
|
||||
+ catch (Exception e)
|
||||
+ {
|
||||
@@ -75,7 +76,7 @@
|
||||
|
||||
if (var8 != null)
|
||||
{
|
||||
@@ -545,8 +591,12 @@
|
||||
@@ -545,8 +592,12 @@
|
||||
|
||||
public void handleChat(Packet3Chat par1Packet3Chat)
|
||||
{
|
||||
@@ -90,7 +91,7 @@
|
||||
}
|
||||
|
||||
public void handleAnimation(Packet18Animation par1Packet18Animation)
|
||||
@@ -633,7 +683,19 @@
|
||||
@@ -633,7 +684,19 @@
|
||||
}
|
||||
else if (par1Packet2Handshake.username.equals("-"))
|
||||
{
|
||||
@@ -111,7 +112,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -646,7 +708,19 @@
|
||||
@@ -646,7 +709,19 @@
|
||||
|
||||
if (var6.equalsIgnoreCase("ok"))
|
||||
{
|
||||
@@ -132,18 +133,18 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -833,6 +907,10 @@
|
||||
@@ -833,6 +908,10 @@
|
||||
case 5:
|
||||
var2.displayGUIBrewingStand(new TileEntityBrewingStand());
|
||||
var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
|
||||
+ break;
|
||||
+
|
||||
+ default:
|
||||
+ ForgeHooksClient.tryMLMPOpenWindow(par1Packet100OpenWindow);
|
||||
+ ModCompatibilityClient.mlmpOpenWindow(par1Packet100OpenWindow);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,6 +1017,19 @@
|
||||
@@ -939,6 +1018,19 @@
|
||||
{
|
||||
((TileEntityMobSpawner)var2).setMobID(EntityList.getStringFromID(par1Packet132TileEntityData.customParam1));
|
||||
}
|
||||
@@ -163,7 +164,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1012,6 +1103,10 @@
|
||||
@@ -1012,6 +1104,10 @@
|
||||
{
|
||||
ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).func_28171_a(par1Packet131MapData.itemData);
|
||||
}
|
||||
@@ -174,7 +175,7 @@
|
||||
else
|
||||
{
|
||||
System.out.println("Unknown itemid: " + par1Packet131MapData.uniqueID);
|
||||
@@ -1114,5 +1209,40 @@
|
||||
@@ -1114,5 +1210,40 @@
|
||||
public void handleCustomPayload(Packet250CustomPayload var1)
|
||||
{
|
||||
ModLoader.receivePacket(var1);
|
||||
|
||||
Reference in new issue
Block a user