Updated patches for FML, moved some extranious code to Forge classes instead of patches.

This commit is contained in:
LexManos 2012-05-27 04:27:15 -07:00
parent ce2a9f270a
commit c708b83425
7 changed files with 162 additions and 136 deletions

View File

@ -5,6 +5,7 @@
package net.minecraft.src.forge;
import net.minecraft.client.Minecraft;
import net.minecraft.src.Block;
import net.minecraft.src.Entity;
import net.minecraft.src.ModLoader;
@ -20,10 +21,13 @@ import net.minecraft.src.WorldClient;
import org.lwjgl.opengl.GL11;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import net.minecraft.src.*;
import net.minecraft.src.forge.packets.ForgePacket;
import org.lwjgl.opengl.GL12;
import static net.minecraft.src.forge.IItemRenderer.ItemRenderType.*;
@ -390,4 +394,109 @@ public class ForgeHooksClient
}
return entry;
}
public static void onLogin(Packet1Login login, NetClientHandler net, NetworkManager netManager)
{
ForgeHooks.onLogin(netManager, login);
String[] channels = MessageManager.getInstance().getRegisteredChannels(netManager);
StringBuilder tmp = new StringBuilder();
tmp.append("Forge");
for(String channel : channels)
{
tmp.append("\0");
tmp.append(channel);
}
Packet250CustomPayload pkt = new Packet250CustomPayload();
pkt.channel = "REGISTER";
try
{
pkt.data = tmp.toString().getBytes("UTF8");
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
pkt.length = pkt.data.length;
net.addToSendQueue(pkt);
}
/**
* We use some of the unused fields in Packet 001 Login to identify the user as having Forge installed.
* This allows modded clients to connect to Vanilla server without crashing.
* It also allows unmodded clients to connect to Forge server without crashing.
* Its a bit of a dirty hack, but it doesn't interrupt the login flow, and its unused data.
* The C->S serverMode is set to the hash code of the string "Forge", this should provide a fairly unique
* identifier so we are certain it is not random, and it is Forge installed.
* The C->S dimension is set to the current Forge build number, in case we need to do any quick version checks.
*/
public static Packet onSendLogin(Packet1Login pkt)
{
pkt.serverMode = ForgePacket.FORGE_ID;
pkt.field_48170_e = ForgeHooks.buildVersion;
return pkt;
}
public static void onCustomPayload(Packet250CustomPayload pkt, NetworkManager net)
{
MessageManager inst = MessageManager.getInstance();
if (pkt.channel.equals("REGISTER"))
{
try
{
String channels = new String(pkt.data, "UTF8");
for (String channel : channels.split("\0"))
{
inst.addActiveChannel(net, channel);
}
}
catch (UnsupportedEncodingException ex)
{
ModLoader.throwException("ForgeHooksClient.onCustomPayload", ex);
}
}
else if (pkt.channel.equals("UNREGISTER"))
{
try
{
String channels = new String(pkt.data, "UTF8");
for (String channel : channels.split("\0"))
{
inst.removeActiveChannel(net, channel);
}
}
catch (UnsupportedEncodingException ex)
{
ModLoader.throwException("ForgeHooksClient.onCustomPayload", ex);
}
}
else
{
inst.dispatchIncomingMessage(net, pkt.channel, pkt.data);
}
}
/**
* This is added for Optifine's convenience. And to explode if a ModMaker is developing.
* @param texture
*/
public static void onTextureLoadPre(String texture)
{
if (Tessellator.renderingWorldRenderer)
{
String msg = String.format("Warning: Texture %s not preloaded, will cause render glitches!", texture);
System.out.println(msg);
if (Tessellator.class.getPackage() != null)
{
if (Tessellator.class.getPackage().equals("net.minecraft.src"))
{
Minecraft mc = ModLoader.getMinecraftInstance();
if (mc.ingameGUI != null)
{
mc.ingameGUI.addChatMessage(msg);
}
}
}
}
}
}

View File

@ -639,7 +639,7 @@ public class ForgeHooks
//This number is incremented every official release, and reset every Minecraft version
public static final int minorVersion = 2;
//This number is incremented every time a interface changes, and reset every Minecraft version
public static final int revisionVersion = 3;
public static final int revisionVersion = 4;
//This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code.
public static final int buildVersion = 0;

View File

@ -541,6 +541,15 @@ public class MinecraftForge
killMinecraft(mod, "MinecraftForge Too Old, need at least " + major + "." + minor + "." + revision);
}
}
/**
* Forge Branding info used by FML to display on the client's main screen.
* @return 'Minecraft Forge vx.x.x.x'
*/
public static String getVersionString()
{
return String.format("Minecraft Forge %d.%d.%d.%d", ForgeHooks.majorVersion, ForgeHooks.minorVersion, ForgeHooks.revisionVersion, ForgeHooks.buildVersion);
}
private static int dungeonLootAttempts = 8;
private static ArrayList<ObjectPair<Float, String>> dungeonMobs = new ArrayList<ObjectPair<Float, String>>();

View File

@ -1,14 +1,15 @@
--- ../src_base/minecraft/net/minecraft/src/EntityItem.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/EntityItem.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,5 +1,7 @@
package net.minecraft.src;
@@ -2,6 +2,8 @@
import cpw.mods.fml.client.FMLClientHandler;
+import net.minecraft.src.forge.ForgeHooks;
+
public class EntityItem extends Entity
{
/** The item stack of this EntityItem. */
@@ -170,7 +172,21 @@
@@ -172,7 +174,21 @@
if (!this.worldObj.isRemote)
{
int var2 = this.item.stackSize;
@ -16,7 +17,7 @@
+
+ if (delayBeforeCanPickup == 0 && !ForgeHooks.onItemPickup(par1EntityPlayer, this))
+ {
+ ModLoader.onItemPickup(par1EntityPlayer, item);
+ FMLClientHandler.instance().notifyItemPickup(this, par1EntityPlayer);
+ this.worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
+ par1EntityPlayer.onItemPickup(this, var2);
+ if (item.stackSize <= 0)
@ -30,4 +31,4 @@
+
if (this.delayBeforeCanPickup == 0 && par1EntityPlayer.inventory.addItemStackToInventory(this.item))
{
if (this.item.itemID == Block.wood.blockID)
FMLClientHandler.instance().notifyItemPickup(this, par1EntityPlayer);

View File

@ -1,11 +1,12 @@
--- ../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,15 @@
@@ -14,9 +14,16 @@
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.logging.Level;
+
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.client.Minecraft;
+import net.minecraft.src.forge.ForgeHooks;
+import net.minecraft.src.forge.ForgeHooksClient;
@ -16,7 +17,7 @@
public class NetClientHandler extends NetHandler
{
@@ -46,6 +54,8 @@
@@ -50,6 +57,8 @@
this.mc = par1Minecraft;
Socket var4 = new Socket(InetAddress.getByName(par2Str), par3);
this.netManager = new NetworkManager(var4, "Client", this);
@ -25,38 +26,15 @@
}
/**
@@ -73,6 +83,30 @@
this.mc.thePlayer.entityId = par1Packet1Login.protocolVersion;
@@ -78,6 +87,7 @@
this.currentServerMaxPlayers = par1Packet1Login.maxPlayers;
((PlayerControllerMP)this.mc.playerController).setCreative(par1Packet1Login.serverMode == 1);
+
+ ForgeHooks.onLogin(netManager, par1Packet1Login);
+
+ String[] channels = MessageManager.getInstance().getRegisteredChannels(netManager);
+ StringBuilder tmp = new StringBuilder();
+ tmp.append("Forge");
+ for(String channel : channels)
+ {
+ tmp.append("\0");
+ tmp.append(channel);
+ }
+ Packet250CustomPayload pkt = new Packet250CustomPayload();
+ pkt.channel = "REGISTER";
+ try
+ {
+ pkt.data = tmp.toString().getBytes("UTF8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ e.printStackTrace();
+ }
+ pkt.length = pkt.data.length;
+ addToSendQueue(pkt);
+
ModLoader.serverConnect(this, par1Packet1Login);
FMLClientHandler.instance().handleServerLogin(par1Packet1Login, this, netManager);
+ ForgeHooksClient.onLogin(par1Packet1Login, this, netManager);
}
@@ -178,6 +212,19 @@
public void handlePickupSpawn(Packet21PickupSpawn par1Packet21PickupSpawn)
@@ -182,6 +192,19 @@
{
var8 = new EntityFallingSand(this.worldClient, var2, var4, var6, Block.dragonEgg.blockID);
}
@ -76,75 +54,50 @@
if (var8 != null)
{
@@ -545,8 +592,12 @@
@@ -547,8 +570,12 @@
public void handleChat(Packet3Chat par1Packet3Chat)
{
- FMLClientHandler.instance().handleChatPacket(par1Packet3Chat);
- this.mc.ingameGUI.addChatMessage(par1Packet3Chat.message);
- ModLoader.serverChat(par1Packet3Chat.message);
+ par1Packet3Chat.message = ForgeHooks.onClientChatRecv(par1Packet3Chat.message);
+ if (par1Packet3Chat.message != null)
+ {
+ FMLClientHandler.instance().handleChatPacket(par1Packet3Chat);
+ this.mc.ingameGUI.addChatMessage(par1Packet3Chat.message);
+ ModLoader.serverChat(par1Packet3Chat.message);
+ }
}
public void handleAnimation(Packet18Animation par1Packet18Animation)
@@ -633,7 +684,19 @@
@@ -638,7 +665,7 @@
}
else if (par1Packet2Handshake.username.equals("-"))
{
- this.addToSendQueue(new Packet1Login(this.mc.session.username, 29));
+ /**
+ * We use some of the unused fields in Packet 001 Login to identify the user as having Forge installed.
+ * This allows modded clients to connect to Vanilla server without crashing.
+ * It also allows unmodded clients to connect to Forge server without crashing.
+ * Its a bit of a dirty hack, but it doesnt interrupt the login flow, and its unused data.
+ * The C->S serverMode is set to the hash code of the string "Forge", this should provide a fairly unique
+ * identifier so we are certain it is not random, and it is Forge installed.
+ * The C->S dimension is set to the current Forge build number, in case we need to do any quick version checks.
+ */
+ Packet1Login pkt = new Packet1Login(mc.session.username, 29);
+ pkt.serverMode = ForgePacket.FORGE_ID;
+ pkt.field_48170_e = ForgeHooks.buildVersion;
+ addToSendQueue(pkt);
+ this.addToSendQueue(ForgeHooksClient.onSendLogin(new Packet1Login(this.mc.session.username, 29)));
}
else
{
@@ -646,7 +709,19 @@
@@ -651,7 +678,7 @@
if (var6.equalsIgnoreCase("ok"))
{
- this.addToSendQueue(new Packet1Login(this.mc.session.username, 29));
+ /**
+ * We use some of the unused fields in Packet 001 Login to identify the user as having Forge installed.
+ * This allows modded clients to connect to Vanilla server without crashing.
+ * It also allows unmodded clients to connect to Forge server without crashing.
+ * Its a bit of a dirty hack, but it doesnt interrupt the login flow, and its unused data.
+ * The C->S serverMode is set to the hash code of the string "Forge", this should provide a fairly unique
+ * identifier so we are certain it is not random, and it is Forge installed.
+ * The C->S dimension is set to the current Forge build number, in case we need to do any quick version checks.
+ */
+ Packet1Login pkt = new Packet1Login(mc.session.username, 29);
+ pkt.serverMode = ForgePacket.FORGE_ID;
+ pkt.field_48170_e = ForgeHooks.buildVersion;
+ addToSendQueue(pkt);
+ this.addToSendQueue(ForgeHooksClient.onSendLogin(new Packet1Login(this.mc.session.username, 29)));
}
else
{
@@ -833,6 +908,10 @@
@@ -832,6 +859,9 @@
case 5:
var2.displayGUIBrewingStand(new TileEntityBrewingStand());
var2.craftingInventory.windowId = par1Packet100OpenWindow.windowId;
+ break;
+
+ default:
+ ModCompatibilityClient.mlmpOpenWindow(par1Packet100OpenWindow);
}
}
@@ -939,6 +1018,19 @@
@@ -938,6 +968,19 @@
{
((TileEntityMobSpawner)var2).setMobID(EntityList.getStringFromID(par1Packet132TileEntityData.customParam1));
}
@ -164,7 +117,7 @@
}
}
@@ -1012,6 +1104,10 @@
@@ -1011,6 +1054,10 @@
{
ItemMap.getMPMapData(par1Packet131MapData.uniqueID, this.mc.theWorld).updateMPMapData(par1Packet131MapData.itemData);
}
@ -175,44 +128,10 @@
else
{
System.out.println("Unknown itemid: " + par1Packet131MapData.uniqueID);
@@ -1114,5 +1210,40 @@
public void handleCustomPayload(Packet250CustomPayload var1)
@@ -1117,5 +1164,6 @@
public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
{
ModLoader.receivePacket(var1);
+ MessageManager inst = MessageManager.getInstance();
+ if (var1.channel.equals("REGISTER"))
+ {
+ try
+ {
+ String channels = new String(var1.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.addActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.throwException("NetClientHandler.handleCustomPayload", ex);
+ }
+ }
+ else if (var1.channel.equals("UNREGISTER"))
+ {
+ try
+ {
+ String channels = new String(var1.data, "UTF8");
+ for (String channel : channels.split("\0"))
+ {
+ inst.removeActiveChannel(netManager, channel);
+ }
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ ModLoader.throwException("NetClientHandler.handleCustomPayload", ex);
+ }
+ }
+ else
+ {
+ inst.dispatchIncomingMessage(netManager, var1.channel, var1.data);
+ }
FMLClientHandler.instance().handlePacket250(par1Packet250CustomPayload);
+ ForgeHooksClient.onCustomPayload(par1Packet250CustomPayload, netManager);
}
}

View File

@ -1,16 +1,15 @@
--- ../src_base/minecraft/net/minecraft/src/RenderEngine.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/RenderEngine.java 0000-00-00 00:00:00.000000000 -0000
@@ -14,6 +14,9 @@
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
+
@@ -27,6 +27,8 @@
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
+import net.minecraft.src.forge.ForgeHooksClient;
+
import org.lwjgl.opengl.GL11;
public class RenderEngine
@@ -48,7 +51,7 @@
{
/** Use mipmaps for all bound textures (unused at present) */
@@ -59,7 +61,7 @@
public boolean blurTexture = false;
/** Texture pack */
@ -19,18 +18,15 @@
/** Missing texture image */
private BufferedImage missingTextureImage = new BufferedImage(64, 64, 2);
@@ -156,6 +159,10 @@
@@ -169,6 +171,7 @@
{
try
{
+ if (Tessellator.renderingWorldRenderer)
+ {
+ System.out.printf("Warning: Texture %s not preloaded, will cause render glitches!\n", par1Str);
+ }
+ ForgeHooksClient.onTextureLoadPre(par1Str);
this.singleIntBuffer.clear();
GLAllocation.generateTextureNames(this.singleIntBuffer);
int var6 = this.singleIntBuffer.get(0);
@@ -199,6 +206,7 @@
@@ -212,6 +215,7 @@
}
this.textureMap.put(par1Str, Integer.valueOf(var6));

View File

@ -1,27 +1,19 @@
--- ../src_base/minecraft/net/minecraft/src/SlotCrafting.java 0000-00-00 00:00:00.000000000 -0000
+++ ../src_work/minecraft/net/minecraft/src/SlotCrafting.java 0000-00-00 00:00:00.000000000 -0000
@@ -1,5 +1,7 @@
@@ -1,5 +1,8 @@
package net.minecraft.src;
+import cpw.mods.fml.client.FMLClientHandler;
+import net.minecraft.src.forge.ForgeHooks;
+
public class SlotCrafting extends Slot
{
/** The craft matrix inventory linked to this result slot. */
@@ -89,8 +91,6 @@
{
this.thePlayer.addStat(AchievementList.bookcase, 1);
}
-
- ModLoader.takenFromCrafting(this.thePlayer, par1ItemStack, this.craftMatrix);
}
/**
@@ -98,6 +98,9 @@
@@ -96,6 +99,9 @@
*/
public void onPickupFromSlot(ItemStack par1ItemStack)
{
+ ModLoader.takenFromCrafting(this.thePlayer, par1ItemStack, this.craftMatrix);
+ FMLClientHandler.instance().onItemCrafted(thePlayer, par1ItemStack, craftMatrix);
+ ForgeHooks.onTakenFromCrafting(thePlayer, par1ItemStack, craftMatrix);
+
this.func_48434_c(par1ItemStack);