Entity spawning works.
This commit is contained in:
parent
5eb2aec84e
commit
5086f22370
23 changed files with 694 additions and 320 deletions
|
@ -44,7 +44,7 @@
|
|||
Display.setVSyncEnabled(this.field_71474_y.field_74352_v);
|
||||
}
|
||||
|
||||
@@ -915,9 +924,11 @@
|
||||
@@ -916,9 +925,11 @@
|
||||
|
||||
if (!this.field_71454_w)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@
|
|||
}
|
||||
|
||||
GL11.glFlush();
|
||||
@@ -1490,11 +1501,15 @@
|
||||
@@ -1491,11 +1502,15 @@
|
||||
|
||||
public void func_71407_l()
|
||||
{
|
||||
|
@ -72,7 +72,7 @@
|
|||
this.field_71424_I.func_76320_a("gui");
|
||||
|
||||
if (!this.field_71445_n)
|
||||
@@ -1977,6 +1992,8 @@
|
||||
@@ -1978,6 +1993,8 @@
|
||||
this.field_71453_ak.func_74428_b();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,4 +37,4 @@
|
|||
+
|
||||
public static enum EnumStatus
|
||||
{
|
||||
OK,
|
||||
OK("OK", 0),
|
||||
|
|
|
@ -1,6 +1,42 @@
|
|||
--- ../src-base/minecraft/net/minecraft/network/NetworkManager.java
|
||||
+++ ../src-work/minecraft/net/minecraft/network/NetworkManager.java
|
||||
@@ -299,6 +299,11 @@
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
+
|
||||
+import cpw.mods.fml.common.network.FMLProxyPacket;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -127,7 +129,7 @@
|
||||
final EnumConnectionState enumconnectionstate = EnumConnectionState.func_150752_a(p_150732_1_);
|
||||
final EnumConnectionState enumconnectionstate1 = (EnumConnectionState)this.field_150746_k.attr(field_150739_c).get();
|
||||
|
||||
- if (enumconnectionstate1 != enumconnectionstate)
|
||||
+ if (enumconnectionstate1 != enumconnectionstate && !( p_150732_1_ instanceof FMLProxyPacket))
|
||||
{
|
||||
field_150735_g.debug("Disabled auto read");
|
||||
this.field_150746_k.config().setAutoRead(false);
|
||||
@@ -135,7 +137,7 @@
|
||||
|
||||
if (this.field_150746_k.eventLoop().inEventLoop())
|
||||
{
|
||||
- if (enumconnectionstate != enumconnectionstate1)
|
||||
+ if (enumconnectionstate != enumconnectionstate1 && !( p_150732_1_ instanceof FMLProxyPacket))
|
||||
{
|
||||
this.func_150723_a(enumconnectionstate);
|
||||
}
|
||||
@@ -149,7 +151,7 @@
|
||||
private static final String __OBFID = "CL_00001241";
|
||||
public void run()
|
||||
{
|
||||
- if (enumconnectionstate != enumconnectionstate1)
|
||||
+ if (enumconnectionstate != enumconnectionstate1 && !( p_150732_1_ instanceof FMLProxyPacket))
|
||||
{
|
||||
NetworkManager.this.func_150723_a(enumconnectionstate);
|
||||
}
|
||||
@@ -299,6 +301,11 @@
|
||||
this.channelRead0(p_channelRead0_1_, (Packet)p_channelRead0_2_);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
--- ../src-base/minecraft/net/minecraft/util/MouseHelper.java
|
||||
+++ ../src-work/minecraft/net/minecraft/util/MouseHelper.java
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
public void func_74372_a()
|
||||
{
|
||||
+ if (Boolean.parseBoolean(System.getProperty("fml.noGrab","false"))) return;
|
||||
Mouse.setGrabbed(true);
|
||||
this.field_74377_a = 0;
|
||||
this.field_74375_b = 0;
|
|
@ -21,8 +21,11 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.entity.Render;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
|
@ -40,6 +43,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.client.registry.KeyBindingRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.DummyModContainer;
|
||||
import cpw.mods.fml.common.DuplicateModsFoundException;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -53,6 +57,7 @@ import cpw.mods.fml.common.ModContainer;
|
|||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import cpw.mods.fml.common.WrongMinecraftVersionException;
|
||||
import cpw.mods.fml.common.network.FMLMessage.EntitySpawnMessage;
|
||||
import cpw.mods.fml.common.network.packet.EntitySpawnAdjustmentPacket;
|
||||
import cpw.mods.fml.common.network.packet.EntitySpawnPacket;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
|
@ -216,7 +221,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
* Also initializes key bindings
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation" })
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
public void finishMinecraftLoading()
|
||||
{
|
||||
if (modsMissing != null || wrongMC != null || customError!=null || dupesFound!=null || modSorting!=null)
|
||||
|
@ -241,6 +246,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
|
||||
// Reload resources
|
||||
client.func_110436_a();
|
||||
RenderingRegistry.instance().loadEntityRenderers((Map<Class<? extends Entity>, Render>)RenderManager.field_78727_a.field_78729_o);
|
||||
loading = false;
|
||||
KeyBindingRegistry.instance().uploadKeyBindingsToGame(client.field_71474_y);
|
||||
}
|
||||
|
@ -373,75 +379,14 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
client.func_147108_a(gui);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet)
|
||||
public WorldClient getWorldClient()
|
||||
{
|
||||
WorldClient wc = client.field_71441_e;
|
||||
return client.field_71441_e;
|
||||
}
|
||||
|
||||
Class<? extends Entity> cls = er.getEntityClass();
|
||||
|
||||
try
|
||||
{
|
||||
Entity entity;
|
||||
if (er.hasCustomSpawning())
|
||||
{
|
||||
entity = er.doCustomSpawning(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = (Entity)(cls.getConstructor(World.class).newInstance(wc));
|
||||
int offset = packet.entityId - entity.func_145782_y();
|
||||
entity.func_145769_d(packet.entityId);
|
||||
entity.func_70012_b(packet.scaledX, packet.scaledY, packet.scaledZ, packet.scaledYaw, packet.scaledPitch);
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving)entity).field_70759_as = packet.scaledHeadYaw;
|
||||
}
|
||||
|
||||
Entity parts[] = entity.func_70021_al();
|
||||
if (parts != null)
|
||||
{
|
||||
for (int j = 0; j < parts.length; j++)
|
||||
{
|
||||
parts[j].func_145769_d(parts[j].func_145782_y() + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entity.field_70118_ct = packet.rawX;
|
||||
entity.field_70117_cu = packet.rawY;
|
||||
entity.field_70116_cv = packet.rawZ;
|
||||
|
||||
if (entity instanceof IThrowableEntity)
|
||||
{
|
||||
Entity thrower = client.field_71439_g.func_145782_y() == packet.throwerId ? client.field_71439_g : wc.func_73045_a(packet.throwerId);
|
||||
((IThrowableEntity)entity).setThrower(thrower);
|
||||
}
|
||||
|
||||
if (packet.metadata != null)
|
||||
{
|
||||
entity.func_70096_w().func_75687_a((List)packet.metadata);
|
||||
}
|
||||
|
||||
if (packet.throwerId > 0)
|
||||
{
|
||||
entity.func_70016_h(packet.speedScaledX, packet.speedScaledY, packet.speedScaledZ);
|
||||
}
|
||||
|
||||
if (entity instanceof IEntityAdditionalSpawnData)
|
||||
{
|
||||
((IEntityAdditionalSpawnData)entity).readSpawnData(packet.dataStream);
|
||||
}
|
||||
|
||||
wc.func_73027_a(packet.entityId, entity);
|
||||
return entity;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.log(Level.SEVERE, e, "A severe problem occurred during the spawning of an entity");
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
public EntityClientPlayerMP getClientPlayerEntity()
|
||||
{
|
||||
return client.field_71439_g;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.logging.Logger;
|
|||
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
|
@ -43,8 +42,6 @@ import com.google.common.collect.Maps;
|
|||
import com.google.common.collect.Sets;
|
||||
|
||||
import cpw.mods.fml.common.network.packet.EntitySpawnAdjustmentPacket;
|
||||
import cpw.mods.fml.common.network.packet.EntitySpawnPacket;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.server.FMLServerHandler;
|
||||
|
@ -328,11 +325,6 @@ public class FMLCommonHandler
|
|||
sidedDelegate.showGuiScreen(clientGuiElement);
|
||||
}
|
||||
|
||||
public Entity spawnEntityIntoClientWorld(EntityRegistration registration, EntitySpawnPacket entitySpawnPacket)
|
||||
{
|
||||
return sidedDelegate.spawnEntityIntoClientWorld(registration, entitySpawnPacket);
|
||||
}
|
||||
|
||||
public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket)
|
||||
{
|
||||
sidedDelegate.adjustEntityLocationOnClient(entitySpawnAdjustmentPacket);
|
||||
|
|
|
@ -12,9 +12,12 @@
|
|||
|
||||
package cpw.mods.fml.common;
|
||||
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
|
||||
import java.io.File;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
@ -33,9 +36,13 @@ import cpw.mods.fml.client.FMLFileResourcePack;
|
|||
import cpw.mods.fml.client.FMLFolderResourcePack;
|
||||
import cpw.mods.fml.common.asm.FMLSanityChecker;
|
||||
import cpw.mods.fml.common.event.FMLConstructionEvent;
|
||||
import cpw.mods.fml.common.network.EntitySpawnHandler;
|
||||
import cpw.mods.fml.common.network.FMLNetworkHandler;
|
||||
import cpw.mods.fml.common.network.FMLRuntimeCodec;
|
||||
import cpw.mods.fml.common.network.NetworkCheckHandler;
|
||||
import cpw.mods.fml.common.network.NetworkModHolder;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.OpenGuiHandler;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
|
@ -45,6 +52,8 @@ import cpw.mods.fml.relauncher.Side;
|
|||
*/
|
||||
public class FMLContainer extends DummyModContainer implements WorldAccessContainer
|
||||
{
|
||||
private EnumMap<Side, EmbeddedChannel> channelPair;
|
||||
|
||||
public FMLContainer()
|
||||
{
|
||||
super(new ModMetadata());
|
||||
|
@ -74,6 +83,7 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai
|
|||
public void modConstruction(FMLConstructionEvent evt)
|
||||
{
|
||||
NetworkRegistry.INSTANCE.register(this, this.getClass(), null, evt.getASMHarvestedData());
|
||||
FMLNetworkHandler.registerChannel(this, evt.getSide());
|
||||
}
|
||||
|
||||
@NetworkCheckHandler
|
||||
|
|
|
@ -32,8 +32,6 @@ public interface IFMLSidedHandler
|
|||
|
||||
void showGuiScreen(Object clientGuiElement);
|
||||
|
||||
Entity spawnEntityIntoClientWorld(EntityRegistration registration, EntitySpawnPacket packet);
|
||||
|
||||
void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket);
|
||||
|
||||
void beginServerLoading(MinecraftServer server);
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
package cpw.mods.fml.common.network;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.network.FMLMessage.EntityMessage;
|
||||
import cpw.mods.fml.common.network.FMLMessage.EntitySpawnMessage;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.common.registry.IThrowableEntity;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
public class EntitySpawnHandler extends SimpleChannelInboundHandler<FMLMessage.EntityMessage> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, EntityMessage msg) throws Exception
|
||||
{
|
||||
if (msg.getClass().equals(FMLMessage.EntitySpawnMessage.class))
|
||||
{
|
||||
spawnEntity(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnEntity(EntityMessage msg)
|
||||
{
|
||||
System.out.println("Spawning entity on client");
|
||||
FMLMessage.EntitySpawnMessage spawnMsg = (EntitySpawnMessage) msg;
|
||||
ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
|
||||
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
|
||||
WorldClient wc = FMLClientHandler.instance().getWorldClient();
|
||||
Class<? extends Entity> cls = er.getEntityClass();
|
||||
try
|
||||
{
|
||||
Entity entity;
|
||||
if (er.hasCustomSpawning())
|
||||
{
|
||||
entity = er.doCustomSpawning(spawnMsg);
|
||||
} else
|
||||
{
|
||||
entity = (Entity) (cls.getConstructor(World.class).newInstance(wc));
|
||||
|
||||
int offset = spawnMsg.entityId - entity.func_145782_y();
|
||||
entity.func_145769_d(spawnMsg.entityId);
|
||||
entity.func_70012_b(spawnMsg.scaledX, spawnMsg.scaledY, spawnMsg.scaledZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
((EntityLiving) entity).field_70759_as = spawnMsg.scaledHeadYaw;
|
||||
}
|
||||
|
||||
Entity parts[] = entity.func_70021_al();
|
||||
if (parts != null)
|
||||
{
|
||||
for (int j = 0; j < parts.length; j++)
|
||||
{
|
||||
parts[j].func_145769_d(parts[j].func_145782_y() + offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entity.field_70118_ct = spawnMsg.rawX;
|
||||
entity.field_70117_cu = spawnMsg.rawY;
|
||||
entity.field_70116_cv = spawnMsg.rawZ;
|
||||
|
||||
EntityClientPlayerMP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
|
||||
if (entity instanceof IThrowableEntity)
|
||||
{
|
||||
Entity thrower = clientPlayer.func_145782_y() == spawnMsg.throwerId ? clientPlayer : wc.func_73045_a(spawnMsg.throwerId);
|
||||
((IThrowableEntity) entity).setThrower(thrower);
|
||||
}
|
||||
|
||||
if (spawnMsg.dataWatcherList != null)
|
||||
{
|
||||
entity.func_70096_w().func_75687_a((List<?>) spawnMsg.dataWatcherList);
|
||||
}
|
||||
|
||||
if (spawnMsg.throwerId > 0)
|
||||
{
|
||||
entity.func_70016_h(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
|
||||
}
|
||||
|
||||
if (entity instanceof IEntityAdditionalSpawnData)
|
||||
{
|
||||
((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
|
||||
}
|
||||
wc.func_73027_a(spawnMsg.entityId, entity);
|
||||
System.out.println("Entity spawned on client");
|
||||
} catch (Exception e)
|
||||
{
|
||||
FMLLog.log(Level.SEVERE, e, "A severe problem occurred during the spawning of an entity");
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,10 +15,10 @@ public abstract class FMLIndexedMessageToMessageCodec<A> extends MessageToMessag
|
|||
private TByteObjectHashMap<Class<? extends A>> discriminators = new TByteObjectHashMap<Class<? extends A>>();
|
||||
private TObjectByteHashMap<Class<? extends A>> types = new TObjectByteHashMap<Class<? extends A>>();
|
||||
|
||||
public FMLIndexedMessageToMessageCodec<A> addDiscriminator(byte discriminator, Class<? extends A> type)
|
||||
public FMLIndexedMessageToMessageCodec<A> addDiscriminator(int discriminator, Class<? extends A> type)
|
||||
{
|
||||
discriminators.put(discriminator, type);
|
||||
types.put(type, discriminator);
|
||||
discriminators.put((byte)discriminator, type);
|
||||
types.put(type, (byte)discriminator);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
195
fml/src/main/java/cpw/mods/fml/common/network/FMLMessage.java
Normal file
195
fml/src/main/java/cpw/mods/fml/common/network/FMLMessage.java
Normal file
|
@ -0,0 +1,195 @@
|
|||
package cpw.mods.fml.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.DataWatcher;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.common.registry.IThrowableEntity;
|
||||
|
||||
public abstract class FMLMessage {
|
||||
public static class OpenGui extends FMLMessage {
|
||||
int windowId;
|
||||
int networkId;
|
||||
int modGuiId;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
@Override
|
||||
void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(windowId);
|
||||
buf.writeInt(networkId);
|
||||
buf.writeInt(modGuiId);
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
}
|
||||
|
||||
@Override
|
||||
void fromBytes(ByteBuf buf)
|
||||
{
|
||||
windowId = buf.readInt();
|
||||
networkId = buf.readInt();
|
||||
modGuiId = buf.readInt();
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class EntityMessage extends FMLMessage {
|
||||
Entity entity;
|
||||
int entityId;
|
||||
public EntityMessage()
|
||||
{
|
||||
|
||||
}
|
||||
EntityMessage(Entity entity)
|
||||
{
|
||||
this.entity = entity;
|
||||
}
|
||||
@Override
|
||||
void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(entity.func_145782_y());
|
||||
}
|
||||
|
||||
@Override
|
||||
void fromBytes(ByteBuf buf)
|
||||
{
|
||||
entityId = buf.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntitySpawnMessage extends EntityMessage {
|
||||
String modId;
|
||||
int modEntityTypeId;
|
||||
int rawX;
|
||||
int rawY;
|
||||
int rawZ;
|
||||
double scaledX;
|
||||
double scaledY;
|
||||
double scaledZ;
|
||||
float scaledYaw;
|
||||
float scaledPitch;
|
||||
float scaledHeadYaw;
|
||||
int throwerId;
|
||||
double speedScaledX;
|
||||
double speedScaledY;
|
||||
double speedScaledZ;
|
||||
@SuppressWarnings("rawtypes")
|
||||
List dataWatcherList;
|
||||
ByteBuf dataStream;
|
||||
|
||||
public EntitySpawnMessage() {}
|
||||
public EntitySpawnMessage(EntityRegistration er, Entity entity, ModContainer modContainer)
|
||||
{
|
||||
super(entity);
|
||||
modId = modContainer.getModId();
|
||||
modEntityTypeId = er.getModEntityId();
|
||||
}
|
||||
@Override
|
||||
void toBytes(ByteBuf buf)
|
||||
{
|
||||
super.toBytes(buf);
|
||||
ByteBufUtils.writeUTF8String(buf, modId);
|
||||
buf.writeInt(modEntityTypeId);
|
||||
// posX, posY, posZ
|
||||
buf.writeInt(MathHelper.func_76128_c(entity.field_70165_t * 32D));
|
||||
buf.writeInt(MathHelper.func_76128_c(entity.field_70163_u * 32D));
|
||||
buf.writeInt(MathHelper.func_76128_c(entity.field_70161_v * 32D));
|
||||
// yaw, pitch
|
||||
buf.writeByte((byte)(entity.field_70177_z * 256.0F / 360.0F));
|
||||
buf.writeByte((byte) (entity.field_70125_A * 256.0F / 360.0F));
|
||||
// head yaw
|
||||
if (entity instanceof EntityLivingBase)
|
||||
{
|
||||
buf.writeByte((byte) (((EntityLivingBase)entity).field_70759_as * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
ByteBuf tmpBuf = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(tmpBuf);
|
||||
try
|
||||
{
|
||||
entity.func_70096_w().func_151509_a(pb);
|
||||
} catch (IOException e)
|
||||
{
|
||||
// Sigh
|
||||
}
|
||||
buf.writeBytes(tmpBuf);
|
||||
|
||||
if (entity instanceof IThrowableEntity)
|
||||
{
|
||||
Entity owner = ((IThrowableEntity)entity).getThrower();
|
||||
buf.writeInt(owner == null ? entity.func_145782_y() : owner.func_145782_y());
|
||||
double maxVel = 3.9D;
|
||||
double mX = entity.field_70159_w;
|
||||
double mY = entity.field_70181_x;
|
||||
double mZ = entity.field_70179_y;
|
||||
if (mX < -maxVel) mX = -maxVel;
|
||||
if (mY < -maxVel) mY = -maxVel;
|
||||
if (mZ < -maxVel) mZ = -maxVel;
|
||||
if (mX > maxVel) mX = maxVel;
|
||||
if (mY > maxVel) mY = maxVel;
|
||||
if (mZ > maxVel) mZ = maxVel;
|
||||
buf.writeInt((int)(mX * 8000D));
|
||||
buf.writeInt((int)(mY * 8000D));
|
||||
buf.writeInt((int)(mZ * 8000D));
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.writeInt(0);
|
||||
}
|
||||
if (entity instanceof IEntityAdditionalSpawnData)
|
||||
{
|
||||
tmpBuf = Unpooled.buffer();
|
||||
((IEntityAdditionalSpawnData)entity).writeSpawnData(tmpBuf);
|
||||
buf.writeBytes(tmpBuf);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
void fromBytes(ByteBuf dat)
|
||||
{
|
||||
super.fromBytes(dat);
|
||||
modId = ByteBufUtils.readUTF8String(dat);
|
||||
modEntityTypeId = dat.readInt();
|
||||
rawX = dat.readInt();
|
||||
rawY = dat.readInt();
|
||||
rawZ = dat.readInt();
|
||||
scaledX = rawX / 32D;
|
||||
scaledY = rawY / 32D;
|
||||
scaledZ = rawZ / 32D;
|
||||
scaledYaw = dat.readByte() * 360F / 256F;
|
||||
scaledPitch = dat.readByte() * 360F / 256F;
|
||||
scaledHeadYaw = dat.readByte() * 360F / 256F;
|
||||
try
|
||||
{
|
||||
dataWatcherList = DataWatcher.func_151508_b(new PacketBuffer(dat));
|
||||
} catch (IOException e)
|
||||
{
|
||||
// Sigh
|
||||
}
|
||||
|
||||
throwerId = dat.readInt();
|
||||
if (throwerId != 0)
|
||||
{
|
||||
speedScaledX = dat.readInt() / 8000D;
|
||||
speedScaledY = dat.readInt() / 8000D;
|
||||
speedScaledZ = dat.readInt() / 8000D;
|
||||
}
|
||||
this.dataStream = dat;
|
||||
}
|
||||
}
|
||||
abstract void toBytes(ByteBuf buf);
|
||||
abstract void fromBytes(ByteBuf buf);
|
||||
}
|
|
@ -12,6 +12,9 @@
|
|||
|
||||
package cpw.mods.fml.common.network;
|
||||
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -28,16 +31,22 @@ import org.apache.logging.log4j.core.helpers.Integers;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cpw.mods.fml.common.FMLContainer;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
|
||||
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage;
|
||||
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class FMLNetworkHandler
|
||||
{
|
||||
public static final int READ_TIMEOUT = Integers.parseInt(System.getProperty("fml.readTimeout","30"),30);
|
||||
public static final int LOGIN_TIMEOUT = Integers.parseInt(System.getProperty("fml.loginTimeout","600"),600);
|
||||
private static EnumMap<Side, EmbeddedChannel> channelPair;
|
||||
|
||||
/* private static final int FML_HASH = Hashing.murmur3_32().hashString("FML").asInt();
|
||||
private static final int PROTOCOL_VERSION = 0x2;
|
||||
|
@ -445,10 +454,22 @@ public class FMLNetworkHandler
|
|||
|
||||
}
|
||||
|
||||
public static Packet getEntitySpawningPacket(Entity field_73132_a)
|
||||
public static Packet getEntitySpawningPacket(Entity entity)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
EntityRegistration er = EntityRegistry.instance().lookupModSpawn(entity.getClass(), false);
|
||||
if (er == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (er.usesVanillaSpawning())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
|
||||
embeddedChannel.writeOutbound(new FMLMessage.EntitySpawnMessage(er, entity, er.getContainer()));
|
||||
FMLProxyPacket result = (FMLProxyPacket) embeddedChannel.outboundMessages().poll();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String checkModList(FMLHandshakeMessage.ModList modListPacket, Side side)
|
||||
|
@ -474,4 +495,22 @@ public class FMLNetworkHandler
|
|||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static void addClientHandlers()
|
||||
{
|
||||
channelPair.get(Side.CLIENT).pipeline().addAfter("FMLRuntimeCodec#0", "GuiHandler", new OpenGuiHandler());
|
||||
channelPair.get(Side.CLIENT).pipeline().addAfter("FMLRuntimeCodec#0", "EntitySpawnHandler", new EntitySpawnHandler());
|
||||
}
|
||||
public static void registerChannel(FMLContainer container, Side side)
|
||||
{
|
||||
channelPair = NetworkRegistry.INSTANCE.newChannel(container, "FML", new FMLRuntimeCodec());
|
||||
EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
|
||||
embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE);
|
||||
|
||||
if (side == Side.CLIENT)
|
||||
{
|
||||
addClientHandlers();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,15 +1,159 @@
|
|||
package cpw.mods.fml.common.network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.OutboundTarget;
|
||||
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class FMLOutboundHandler extends ChannelOutboundHandlerAdapter {
|
||||
public static final AttributeKey<OutboundTarget> FML_MESSAGETARGET = new AttributeKey<OutboundTarget>("fml:outboundTarget");
|
||||
public static final AttributeKey<Object> FML_MESSAGETARGETARGS = new AttributeKey<Object>("fml:outboundTargetArgs");
|
||||
public enum OutboundTarget {
|
||||
NOWHERE
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
},
|
||||
PLAYER
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof EntityPlayerMP))
|
||||
{
|
||||
throw new RuntimeException("PLAYER target expects a Player arg");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
EntityPlayerMP player = (EntityPlayerMP) args;
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
return ImmutableList.of(dispatcher);
|
||||
}
|
||||
},
|
||||
ALL
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
DIMENSION
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof Integer))
|
||||
{
|
||||
throw new RuntimeException("DIMENSION expects an integer argument");
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
int dimension = (Integer)args;
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
if (dimension == player.field_71093_bK)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
ALLAROUNDPOINT
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof TargetPoint))
|
||||
{
|
||||
throw new RuntimeException("ALLAROUNDPOINT expects a TargetPoint argument");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
TargetPoint tp = (TargetPoint)args;
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
if (player.field_71093_bK == tp.dimension)
|
||||
{
|
||||
double d4 = tp.x - player.field_70165_t;
|
||||
double d5 = tp.y - player.field_70163_u;
|
||||
double d6 = tp.z - player.field_70161_v;
|
||||
|
||||
if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
TOSERVER
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
throw new RuntimeException("Cannot set TOSERVER as a target on the server");
|
||||
}
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
NetworkManager clientConnection = FMLCommonHandler.instance().getClientToServerNetworkManager();
|
||||
return clientConnection == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(clientConnection.channel().attr(NetworkDispatcher.FML_DISPATCHER).get());
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void validateArgs(Object args);
|
||||
public abstract List<NetworkDispatcher> selectNetworks(Object args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
|
||||
{
|
||||
|
@ -25,13 +169,19 @@ public class FMLOutboundHandler extends ChannelOutboundHandlerAdapter {
|
|||
}
|
||||
else
|
||||
{
|
||||
outboundTarget = ctx.channel().attr(NetworkRegistry.FML_MESSAGETARGET).get();
|
||||
args = ctx.channel().attr(NetworkRegistry.FML_MESSAGETARGETARGS).get();
|
||||
outboundTarget = ctx.channel().attr(FML_MESSAGETARGET).get();
|
||||
args = ctx.channel().attr(FML_MESSAGETARGETARGS).get();
|
||||
|
||||
outboundTarget.validateArgs(args);
|
||||
}
|
||||
List<NetworkDispatcher> dispatchers = outboundTarget.selectNetworks(args);
|
||||
|
||||
// This will drop the messages into the output queue at the embedded channel
|
||||
if (dispatchers == null)
|
||||
{
|
||||
ctx.write(msg, promise);
|
||||
return;
|
||||
}
|
||||
for (NetworkDispatcher dispatcher : dispatchers)
|
||||
{
|
||||
dispatcher.sendProxy((FMLProxyPacket) msg);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cpw.mods.fml.common.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
public class FMLRuntimeCodec extends FMLIndexedMessageToMessageCodec<FMLMessage> {
|
||||
public FMLRuntimeCodec()
|
||||
{
|
||||
addDiscriminator(1,FMLMessage.OpenGui.class);
|
||||
addDiscriminator(2,FMLMessage.EntitySpawnMessage.class);
|
||||
}
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, FMLMessage msg, ByteBuf target) throws Exception
|
||||
{
|
||||
msg.toBytes(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source, FMLMessage msg)
|
||||
{
|
||||
msg.fromBytes(source);
|
||||
}
|
||||
|
||||
}
|
|
@ -19,17 +19,13 @@ import io.netty.handler.codec.MessageToMessageCodec;
|
|||
import io.netty.util.AttributeKey;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
@ -37,7 +33,6 @@ import cpw.mods.fml.common.FMLLog;
|
|||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
/**
|
||||
|
@ -57,8 +52,6 @@ public enum NetworkRegistry
|
|||
*/
|
||||
public static final AttributeKey<String> FML_CHANNEL = new AttributeKey<String>("fml:channelName");
|
||||
public static final AttributeKey<Side> CHANNEL_SOURCE = new AttributeKey<Side>("fml:channelSource");
|
||||
public static final AttributeKey<OutboundTarget> FML_MESSAGETARGET = new AttributeKey<OutboundTarget>("fml:outboundTarget");
|
||||
public static final AttributeKey<Object> FML_MESSAGETARGETARGS = new AttributeKey<Object>("fml:outboundTargetArgs");
|
||||
public static final AttributeKey<ModContainer> MOD_CONTAINER = new AttributeKey<ModContainer>("fml:modContainer");
|
||||
|
||||
public static final byte FML_PROTOCOL = 1;
|
||||
|
@ -84,125 +77,6 @@ public enum NetworkRegistry
|
|||
public final double range;
|
||||
public final int dimension;
|
||||
}
|
||||
public enum OutboundTarget {
|
||||
PLAYER
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof EntityPlayerMP))
|
||||
{
|
||||
throw new RuntimeException("PLAYER target expects a Player arg");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
EntityPlayerMP player = (EntityPlayerMP) args;
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
return ImmutableList.of(dispatcher);
|
||||
}
|
||||
},
|
||||
ALL
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
DIMENSION
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof Integer))
|
||||
{
|
||||
throw new RuntimeException("DIMENSION expects an integer argument");
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
int dimension = (Integer)args;
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
if (dimension == player.field_71093_bK)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
ALLAROUNDPOINT
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
if (!(args instanceof TargetPoint))
|
||||
{
|
||||
throw new RuntimeException("ALLAROUNDPOINT expects a TargetPoint argument");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
TargetPoint tp = (TargetPoint)args;
|
||||
ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
|
||||
for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
|
||||
{
|
||||
if (player.field_71093_bK == tp.dimension)
|
||||
{
|
||||
double d4 = tp.x - player.field_70165_t;
|
||||
double d5 = tp.y - player.field_70163_u;
|
||||
double d6 = tp.z - player.field_70161_v;
|
||||
|
||||
if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
|
||||
{
|
||||
NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
|
||||
builder.add(dispatcher);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
},
|
||||
TOSERVER
|
||||
{
|
||||
@Override
|
||||
public void validateArgs(Object args)
|
||||
{
|
||||
throw new RuntimeException("Cannot set TOSERVER as a target on the server");
|
||||
}
|
||||
@Override
|
||||
public List<NetworkDispatcher> selectNetworks(Object args)
|
||||
{
|
||||
NetworkManager clientConnection = FMLCommonHandler.instance().getClientToServerNetworkManager();
|
||||
return clientConnection == null ? ImmutableList.<NetworkDispatcher>of() : ImmutableList.of(clientConnection.channel().attr(NetworkDispatcher.FML_DISPATCHER).get());
|
||||
}
|
||||
};
|
||||
|
||||
public abstract void validateArgs(Object args);
|
||||
public abstract List<NetworkDispatcher> selectNetworks(Object args);
|
||||
}
|
||||
|
||||
static class FMLEmbeddedChannel extends EmbeddedChannel {
|
||||
public FMLEmbeddedChannel(String channelName, Side source, ChannelHandler... handlers)
|
||||
{
|
||||
|
@ -214,7 +88,7 @@ public enum NetworkRegistry
|
|||
this.attr(FML_CHANNEL).set(channelName);
|
||||
this.attr(CHANNEL_SOURCE).set(source);
|
||||
this.attr(MOD_CONTAINER).setIfAbsent(container);
|
||||
this.pipeline().addFirst(new FMLOutboundHandler());
|
||||
this.pipeline().addFirst("fml:outbound",new FMLOutboundHandler());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package cpw.mods.fml.common.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.network.FMLMessage.OpenGui;
|
||||
|
||||
public class OpenGuiHandler extends SimpleChannelInboundHandler<FMLMessage.OpenGui> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, OpenGui msg) throws Exception
|
||||
{
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().field_71439_g;
|
||||
player.openGui(msg.networkId, msg.modGuiId, player.field_70170_p, msg.x, msg.y, msg.z);
|
||||
player.field_71070_bA.field_75152_c = msg.windowId;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package cpw.mods.fml.common.network.handshake;
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOutboundHandler;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import io.netty.util.AttributeKey;
|
||||
|
@ -9,6 +11,7 @@ import io.netty.util.concurrent.Future;
|
|||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.util.concurrent.ScheduledFuture;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -27,7 +30,7 @@ import cpw.mods.fml.common.network.FMLProxyPacket;
|
|||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> {
|
||||
public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> implements ChannelOutboundHandler {
|
||||
private static enum ConnectionState {
|
||||
OPENING, AWAITING_HANDSHAKE, HANDSHAKING, CONNECTED;
|
||||
}
|
||||
|
@ -283,14 +286,70 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet> {
|
|||
|
||||
public void sendProxy(FMLProxyPacket msg)
|
||||
{
|
||||
if (side == Side.CLIENT)
|
||||
manager.func_150725_a(msg.toC17Packet());
|
||||
else
|
||||
manager.func_150725_a(msg.toS3FPacket());
|
||||
manager.func_150725_a(msg);
|
||||
}
|
||||
|
||||
public void rejectHandshake(String result)
|
||||
{
|
||||
kickWithMessage(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception
|
||||
{
|
||||
ctx.bind(localAddress, promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception
|
||||
{
|
||||
ctx.connect(remoteAddress, localAddress, promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
|
||||
{
|
||||
ctx.disconnect(promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
|
||||
{
|
||||
ctx.close(promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
|
||||
{
|
||||
ctx.deregister(promise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ChannelHandlerContext ctx) throws Exception
|
||||
{
|
||||
ctx.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
|
||||
{
|
||||
if (msg instanceof FMLProxyPacket)
|
||||
{
|
||||
if (side == Side.CLIENT)
|
||||
ctx.write(((FMLProxyPacket) msg).toC17Packet(), promise);
|
||||
else
|
||||
ctx.write(((FMLProxyPacket) msg).toS3FPacket(), promise);
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx.write(msg, promise);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush(ChannelHandlerContext ctx) throws Exception
|
||||
{
|
||||
ctx.flush();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package cpw.mods.fml.common.network.packet;
|
||||
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.common.network.packet.PacketManager.PacketExecutor;
|
||||
|
||||
public class OpenGuiHandler extends PacketExecutor<OpenGuiPacket, NetHandlerPlayClient> {
|
||||
@Override
|
||||
public Void call() throws Exception
|
||||
{
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().field_71439_g;
|
||||
player.openGui(packet.networkId, packet.modGuiId, player.field_70170_p, packet.x, packet.y, packet.z);
|
||||
player.field_71070_bA.field_75152_c = packet.windowId;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Forge Mod Loader
|
||||
* Copyright (c) 2012-2013 cpw.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v2.1
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
*
|
||||
* Contributors:
|
||||
* cpw - implementation
|
||||
*/
|
||||
|
||||
package cpw.mods.fml.common.network.packet;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
public class OpenGuiPacket extends FMLOldPacket
|
||||
{
|
||||
int windowId;
|
||||
int networkId;
|
||||
int modGuiId;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
@Override
|
||||
byte[] generatePacketData(Object... data)
|
||||
{
|
||||
ByteArrayDataOutput dat = ByteStreams.newDataOutput();
|
||||
dat.writeInt((Integer) data[0]); // windowId
|
||||
dat.writeInt((Integer) data[1]); // networkId
|
||||
dat.writeInt((Integer) data[2]); // modGuiId
|
||||
dat.writeInt((Integer) data[3]); // x
|
||||
dat.writeInt((Integer) data[4]); // y
|
||||
dat.writeInt((Integer) data[5]); // z
|
||||
return dat.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FMLOldPacket consumePacketData(byte[] data)
|
||||
{
|
||||
ByteArrayDataInput dat = ByteStreams.newDataInput(data);
|
||||
windowId = dat.readInt();
|
||||
networkId = dat.readInt();
|
||||
modGuiId = dat.readInt();
|
||||
x = dat.readInt();
|
||||
y = dat.readInt();
|
||||
z = dat.readInt();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.network.packet.EntitySpawnPacket;
|
||||
import cpw.mods.fml.common.network.FMLMessage.EntitySpawnMessage;
|
||||
|
||||
public class EntityRegistry
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ public class EntityRegistry
|
|||
private int trackingRange;
|
||||
private int updateFrequency;
|
||||
private boolean sendsVelocityUpdates;
|
||||
private Function<EntitySpawnPacket, Entity> customSpawnCallback;
|
||||
private Function<EntitySpawnMessage, Entity> customSpawnCallback;
|
||||
private boolean usesVanillaSpawning;
|
||||
public EntityRegistration(ModContainer mc, Class<? extends Entity> entityClass, String entityName, int id, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates)
|
||||
{
|
||||
|
@ -100,11 +100,11 @@ public class EntityRegistry
|
|||
{
|
||||
return customSpawnCallback != null;
|
||||
}
|
||||
public Entity doCustomSpawning(EntitySpawnPacket packet) throws Exception
|
||||
public Entity doCustomSpawning(EntitySpawnMessage spawnMsg) throws Exception
|
||||
{
|
||||
return customSpawnCallback.apply(packet);
|
||||
return customSpawnCallback.apply(spawnMsg);
|
||||
}
|
||||
public void setCustomSpawning(Function<EntitySpawnPacket, Entity> callable, boolean usesVanillaSpawning)
|
||||
public void setCustomSpawning(Function<EntitySpawnMessage, Entity> callable, boolean usesVanillaSpawning)
|
||||
{
|
||||
this.customSpawnCallback = callable;
|
||||
this.usesVanillaSpawning = usesVanillaSpawning;
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
package cpw.mods.fml.common.registry;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* A interface for Entities that need extra information to be communicated
|
||||
|
@ -25,9 +24,9 @@ public interface IEntityAdditionalSpawnData
|
|||
* Called by the server when constructing the spawn packet.
|
||||
* Data should be added to the provided stream.
|
||||
*
|
||||
* @param data The packet data stream
|
||||
* @param buffer The packet data stream
|
||||
*/
|
||||
public void writeSpawnData(ByteArrayDataOutput data);
|
||||
public void writeSpawnData(ByteBuf buffer);
|
||||
|
||||
/**
|
||||
* Called by the client when it receives a Entity spawn packet.
|
||||
|
@ -35,5 +34,5 @@ public interface IEntityAdditionalSpawnData
|
|||
*
|
||||
* @param data The packet data stream
|
||||
*/
|
||||
public void readSpawnData(ByteArrayDataInput data);
|
||||
public void readSpawnData(ByteBuf additionalData);
|
||||
}
|
||||
|
|
|
@ -142,13 +142,6 @@ public class FMLServerHandler implements IFMLSidedHandler
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet)
|
||||
{
|
||||
// NOOP
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ public net.minecraft.entity.EntityList.field_75623_d #idToClassMap
|
|||
##public bba.h #FD:RenderEngine/field_78367_h #textureList # -- MISSING MAPPING # -- MISSING MAPPING
|
||||
##public bge.g #FD:RenderEngine/field_78366_k #texturePack # -- MISSING MAPPING
|
||||
## RenderManager
|
||||
#public bgl.q #FD:RenderManager/field_78729_o #renderers
|
||||
public net.minecraft.client.renderer.entity.RenderManager/field_78729_o #renderers
|
||||
## RenderBlocks - everything
|
||||
#public bfr.* #FD:RenderBlocks/*
|
||||
#public bfr.*() #MD:RenderBlocks/*
|
||||
|
|
Loading…
Reference in a new issue