added back some proxy code, fixing server load, fix #1447

This commit is contained in:
SpaceToad 2014-02-18 20:42:57 +01:00
parent f6240d4285
commit 873c39f314
8 changed files with 161 additions and 211 deletions

View file

@ -8,7 +8,11 @@
*/
package buildcraft.builders.network;
import buildcraft.BuildCraftBuilders;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
import buildcraft.builders.TileArchitect;
import buildcraft.builders.TileBlueprintLibrary;
import buildcraft.core.network.BuildCraftChannelHandler;
@ -17,17 +21,7 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayloadArrays;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import cpw.mods.fml.common.network.NetworkRegistry;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
public class PacketHandlerBuilders extends BuildCraftChannelHandler {
@ -36,11 +30,11 @@ public class PacketHandlerBuilders extends BuildCraftChannelHandler {
super.decodeInto(ctx, data, packet);
try {
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler);
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) {
case PacketIds.ARCHITECT_NAME:
onArchitectName(player, (PacketUpdate) packet);

View file

@ -11,35 +11,30 @@ package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.proxy.CoreProxy;
import cpw.mods.fml.common.network.NetworkRegistry;
public class PacketHandler extends BuildCraftChannelHandler {
private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException {
World world = player.worldObj;
World world = player.worldObj;
if (!packet.targetExists(world)) {
return;
}
TileEntity entity = packet.getTarget(world);
if (!(entity instanceof ISynchronizedTile)) {
return;
}
ISynchronizedTile tile = (ISynchronizedTile) entity;
tile.handleUpdatePacket(packet);
tile.postPacketHandling(packet);
@ -48,13 +43,13 @@ public class PacketHandler extends BuildCraftChannelHandler {
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
try {
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler);
EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) {
case PacketIds.TILE_UPDATE: {
onTileUpdate(player, (PacketTileUpdate) packet);
@ -64,13 +59,13 @@ public class PacketHandler extends BuildCraftChannelHandler {
case PacketIds.STATE_UPDATE: {
PacketTileState pkt = (PacketTileState) packet;
World world = player.worldObj;
TileEntity tile = world.getTileEntity(pkt.posX, pkt.posY, pkt.posZ);
if (tile instanceof ISyncedTile) {
pkt.applyStates(data, (ISyncedTile) tile);
}
break;
}

View file

@ -8,45 +8,36 @@
*/
package buildcraft.core.proxy;
import buildcraft.api.core.LaserKind;
import buildcraft.core.EntityBlock;
import buildcraft.core.ItemBlockBuildCraft;
import buildcraft.core.network.BuildCraftPacket;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.registry.GameRegistry;
import java.io.File;
import java.util.List;
import java.util.Random;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.network.Packet;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import buildcraft.api.core.LaserKind;
import buildcraft.core.EntityBlock;
import buildcraft.core.ItemBlockBuildCraft;
import com.mojang.authlib.GameProfile;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.registry.GameRegistry;
/**
* This class comes from the old times where there were two Minecrafts
* codebases, one client and one server. We should slowly aim at removing it.
*/
@Deprecated
public class CoreProxy {
@SidedProxy(clientSide = "buildcraft.core.proxy.CoreProxyClient", serverSide = "buildcraft.core.proxy.CoreProxy")
@ -140,7 +131,7 @@ public class CoreProxy {
private EntityPlayer createNewPlayer(World world) {
EntityPlayer player = new EntityPlayer(world, new GameProfile (null, "[BuildCraft]")) {
@Override
public void addChatMessage(IChatComponent var1) {
public void addChatMessage(IChatComponent var1) {
}
@Override
@ -159,9 +150,9 @@ public class CoreProxy {
private EntityPlayer createNewPlayer(World world, int x, int y, int z) {
EntityPlayer player = new EntityPlayer(world, new GameProfile (null, "[BuildCraft]")) {
@Override
public void addChatMessage(IChatComponent var1) {
public void addChatMessage(IChatComponent var1) {
}
@Override
public boolean canCommandSenderUseCommand(int var1, String var2) {
return false;
@ -170,7 +161,7 @@ public class CoreProxy {
@Override
public ChunkCoordinates getPlayerCoordinates() {
return null;
}
}
};
player.posX = x;
player.posY = y;
@ -204,4 +195,16 @@ public class CoreProxy {
public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) {
return new EntityBlock(world, i, j, k, iSize, jSize, kSize);
}
/**
* This function returns either the player from the handler if it's on the
* server, or directly from the minecraft instance if it's the client.
*/
public EntityPlayer getPlayerFromNetHandler (INetHandler handler) {
if (handler instanceof NetHandlerPlayServer) {
return ((NetHandlerPlayServer) handler).playerEntity;
} else {
return null;
}
}
}

View file

@ -8,6 +8,23 @@
*/
package buildcraft.core.proxy;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.LaserKind;
import buildcraft.core.EntityBlock;
@ -21,32 +38,11 @@ import buildcraft.core.render.RenderRobot;
import buildcraft.core.render.RenderingEntityBlocks;
import buildcraft.core.render.RenderingMarkers;
import buildcraft.transport.render.TileEntityPickupFX;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import java.io.File;
import java.util.List;
import com.mojang.authlib.GameProfile;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
public class CoreProxyClient extends CoreProxy {
@ -136,7 +132,7 @@ public class CoreProxyClient extends CoreProxy {
return null;
}
};
return player;
}
@ -167,4 +163,17 @@ public class CoreProxyClient extends CoreProxy {
}
return eb;
}
/**
* This function returns either the player from the handler if it's on the
* server, or directly from the minecraft instance if it's the client.
*/
@Override
public EntityPlayer getPlayerFromNetHandler (INetHandler handler) {
if (handler instanceof NetHandlerPlayServer) {
return ((NetHandlerPlayServer) handler).playerEntity;
} else {
return Minecraft.getMinecraft().thePlayer;
}
}
}

View file

@ -8,6 +8,28 @@
*/
package buildcraft.core.utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.LaserKind;
@ -25,52 +47,10 @@ import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.ISynchronizedTile;
import buildcraft.core.network.PacketTileUpdate;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.TileEngine;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagEnd;
import net.minecraft.nbt.NBTTagFloat;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagIntArray;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagLong;
import net.minecraft.nbt.NBTTagShort;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
public class Utils {
@ -78,12 +58,12 @@ public class Utils {
private static final List<ForgeDirection> directions = new ArrayList<ForgeDirection>(Arrays.asList(ForgeDirection.VALID_DIRECTIONS));
public enum NBTTag_Types {
NBTTagEnd, NBTTagByte, NBTTagShort,
NBTTagInt, NBTTagLong, NBTTagFloat,
NBTTagEnd, NBTTagByte, NBTTagShort,
NBTTagInt, NBTTagLong, NBTTagFloat,
NBTTagDouble, NBTTagByteArray, NBTTagString,
NBTTagList, NBTTagCompound, NBTTagIntArray
}
/* IINVENTORY HELPERS */
/**
* Tries to add the passed stack to any valid inventories around the given
@ -428,8 +408,8 @@ public class Utils {
}
return slots;
}
public static void writeUTF (ByteBuf data, String str) {
public static void writeUTF (ByteBuf data, String str) {
try {
byte [] b = str.getBytes("UTF-8");
data.writeInt (b.length);
@ -439,19 +419,19 @@ public class Utils {
data.writeInt (0);
}
}
public static String readUTF (ByteBuf data) {
public static String readUTF (ByteBuf data) {
try {
int len = data.readInt();
byte [] b = new byte [len];
data.readBytes(b);
return new String (b, "UTF-8");
} catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
public static void writeNBT (ByteBuf data, NBTTagCompound nbt) {
try {
byte[] compressed = CompressedStreamTools.compress(nbt);
@ -459,9 +439,9 @@ public class Utils {
data.writeBytes(compressed);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static NBTTagCompound readNBT(ByteBuf data) {
try {
short length = data.readShort();
@ -473,18 +453,18 @@ public class Utils {
return null;
}
}
public static void writeStack (ByteBuf data, ItemStack stack) {
if (stack == null) {
data.writeBoolean(false);
} else {
data.writeBoolean(true);
NBTTagCompound nbt = new NBTTagCompound();
NBTTagCompound nbt = new NBTTagCompound();
stack.writeToNBT(nbt);
Utils.writeNBT(data, nbt);
}
}
public static ItemStack readStack(ByteBuf data) {
if (!data.readBoolean()) {
@ -494,35 +474,23 @@ public class Utils {
return ItemStack.loadItemStackFromNBT(nbt);
}
}
/**
* This subprogram transforms a packet into a FML packet to be send in the
* minecraft default packet mechanism. This always use BC-CORE as a
* minecraft default packet mechanism. This always use BC-CORE as a
* channel, and as a result, should use discriminators declared there.
*
*
* WARNING! The implementation of this subprogram relies on the internal
* behavior of #FMLIndexedMessageToMessageCodec (in particular the encode
* member). It is probably opening a maintenance issue and should be
* replaced eventually by some more solid mechanism.
* replaced eventually by some more solid mechanism.
*/
public static FMLProxyPacket toPacket (BuildCraftPacket packet, int discriminator) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte((byte) discriminator);
packet.writeData(buf);
return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE");
}
/**
* This function returns either the player from the handler if it's on the
* server, or directly from the minecraft instance if it's the client.
*/
public static EntityPlayer getPlayerFromNetHandler (INetHandler handler) {
if (handler instanceof NetHandlerPlayServer) {
return ((NetHandlerPlayServer) handler).playerEntity;
} else {
return Minecraft.getMinecraft().thePlayer;
}
}
}

View file

@ -8,39 +8,35 @@
*/
package buildcraft.factory.network;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.factory.TileRefinery;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.factory.TileRefinery;
import cpw.mods.fml.common.network.NetworkRegistry;
public class PacketHandlerFactory extends BuildCraftChannelHandler {
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
try {
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler);
EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) {
@ -73,7 +69,7 @@ public class PacketHandlerFactory extends BuildCraftChannelHandler {
TileRefinery tile = getRefinery(playerEntity.worldObj, packet.posX, packet.posY, packet.posZ);
if (tile == null || packet.payload == null)
return;
ByteBuf stream = ((PacketPayloadStream)packet.payload).stream;
tile.setFilter(stream.readByte(), FluidRegistry.getFluid(stream.readShort()));

View file

@ -8,6 +8,13 @@
*/
package buildcraft.silicon.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketCoordinates;
@ -15,39 +22,27 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.silicon.TileAdvancedCraftingTable;
import buildcraft.silicon.TileAssemblyTable;
import buildcraft.silicon.TileAssemblyTable.SelectionMessage;
import buildcraft.silicon.gui.ContainerAssemblyTable;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class PacketHandlerSilicon extends BuildCraftChannelHandler {
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
try {
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler);
EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) {
case PacketIds.SELECTION_ASSEMBLY_SEND:
case PacketIds.SELECTION_ASSEMBLY_SEND:
onSelectionUpdate(player, (PacketNBT) packet);
break;
case PacketIds.SELECTION_ASSEMBLY:
@ -104,7 +99,7 @@ public class PacketHandlerSilicon extends BuildCraftChannelHandler {
/**
* Sends the current selection on the assembly table to a player.
*
*
* @param player
* @param packet
*/
@ -119,7 +114,7 @@ public class PacketHandlerSilicon extends BuildCraftChannelHandler {
/**
* Sets the selection on an assembly table according to player request.
*
*
* @param player
* @param packetA
*/
@ -136,7 +131,7 @@ public class PacketHandlerSilicon extends BuildCraftChannelHandler {
/**
* Sets the packet into the advanced workbench
*
*
* @param player
* @param packet1
*/

View file

@ -8,6 +8,13 @@
*/
package buildcraft.transport.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.network.INetHandler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketCoordinates;
@ -15,35 +22,18 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.pipes.PipeItemsDiamond;
import buildcraft.transport.pipes.PipeItemsEmerald;
import cpw.mods.fml.common.network.FMLOutboundHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class PacketHandlerTransport extends BuildCraftChannelHandler {
/**
* TODO: A lot of this is based on the player to retrieve the world.
* TODO: A lot of this is based on the player to retrieve the world.
* Passing a dimension id would be more appropriate. More generally, it
* seems like a lot of these packets could be replaced with tile-based
* RPCs.
@ -52,8 +42,8 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler {
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
try {
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler);
INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
@ -89,17 +79,17 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler {
/**
* SERVER SIDE *
*/
case PacketIds.DIAMOND_PIPE_SELECT: {
case PacketIds.DIAMOND_PIPE_SELECT: {
onDiamondPipeSelect(player, (PacketSlotChange) packet);
break;
}
case PacketIds.EMERALD_PIPE_SELECT: {
case PacketIds.EMERALD_PIPE_SELECT: {
onEmeraldPipeSelect(player, (PacketSlotChange) packet);
break;
}
case PacketIds.GATE_REQUEST_INIT:
case PacketIds.GATE_REQUEST_INIT:
onGateInitRequest(player, (PacketCoordinates) packet);
break;