New stuff on the ModLoader! Risu has been busy. Closes #114

This commit is contained in:
Christian 2012-10-02 08:29:12 -04:00
parent 9a8a38d345
commit 0ed0d284b5
5 changed files with 58 additions and 5 deletions

View file

@ -12,6 +12,9 @@ import net.minecraft.src.Entity;
import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.KeyBinding;
import net.minecraft.src.NetClientHandler;
import net.minecraft.src.NetHandler;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.Render;
import net.minecraft.src.RenderManager;
@ -23,6 +26,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.MapDifference;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
@ -150,4 +154,24 @@ public class ModLoaderClientHelper implements IModLoaderSidedHelper
{
((net.minecraft.src.BaseMod)mod).clientCustomPayload(client.field_71439_g.field_71174_a, packet);
}
private Map<NetworkManager,NetHandler> managerLookups = new MapMaker().weakKeys().weakValues().makeMap();
@Override
public void clientConnectionOpened(NetHandler netClientHandler, NetworkManager manager, BaseModProxy mod)
{
managerLookups.put(manager, netClientHandler);
((BaseMod)mod).clientConnect((NetClientHandler)netClientHandler);
}
@Override
public boolean clientConnectionClosed(NetworkManager manager, BaseModProxy mod)
{
if (managerLookups.containsKey(manager))
{
((BaseMod)mod).clientDisconnect((NetClientHandler) managerLookups.get(manager));
return true;
}
return false;
}
}

View file

@ -144,7 +144,7 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
generateNether(w, random, chunkX << 4, chunkZ << 4);
}
}
@Override
public final boolean handleCommand(String command, Object... data)
{
@ -308,6 +308,25 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr
{
}
/**
* Called when a client connects
* @param handler
*/
@SideOnly(CLIENT)
public void clientConnect(NetClientHandler handler)
{
}
/**
* Called when the client disconnects
* @param handler
*/
@SideOnly(CLIENT)
public void clientDisconnect(NetClientHandler handler)
{
}
/**
* Called client side to receive a custom payload for this mod
*

View file

@ -21,6 +21,7 @@ import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiScreen;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NetClientHandler;
import net.minecraft.src.NetHandler;
import net.minecraft.src.NetServerHandler;
import net.minecraft.src.NetworkManager;

View file

@ -4,6 +4,8 @@ import cpw.mods.fml.common.network.EntitySpawnPacket;
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetHandler;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet250CustomPayload;
public interface IModLoaderSidedHelper
@ -17,4 +19,8 @@ public interface IModLoaderSidedHelper
void sendClientPacket(BaseModProxy mod, Packet250CustomPayload packet);
void clientConnectionOpened(NetHandler netClientHandler, NetworkManager manager, BaseModProxy mod);
boolean clientConnectionClosed(NetworkManager manager, BaseModProxy mod);
}

View file

@ -33,14 +33,17 @@ public class ModLoaderConnectionHandler implements IConnectionHandler
@Override
public void connectionOpened(NetHandler netClientHandler, String server, int port, NetworkManager manager)
{
// noop
ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
}
@Override
public void connectionClosed(NetworkManager manager)
{
mod.serverDisconnect();
mod.onClientLogout(manager);
if (!ModLoaderHelper.sidedHelper.clientConnectionClosed(manager, mod))
{
mod.serverDisconnect();
mod.onClientLogout(manager);
}
}
@Override
@ -52,7 +55,7 @@ public class ModLoaderConnectionHandler implements IConnectionHandler
@Override
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, NetworkManager manager)
{
// noop
ModLoaderHelper.sidedHelper.clientConnectionOpened(netClientHandler, manager, mod);
}
}