progress made in MC 1.7 network support

This commit is contained in:
SpaceToad 2014-01-13 20:26:16 +01:00
parent 13213cd59d
commit 14003341e3
41 changed files with 384 additions and 231 deletions

View file

@ -64,6 +64,7 @@ import buildcraft.core.InterModComms;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.core.blueprints.BptPlayerIndex; import buildcraft.core.blueprints.BptPlayerIndex;
import buildcraft.core.blueprints.BptRootIndex; import buildcraft.core.blueprints.BptRootIndex;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BCLog; import buildcraft.core.utils.BCLog;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
@ -79,9 +80,11 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.TreeMap; import java.util.TreeMap;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -93,8 +96,7 @@ import net.minecraftforge.common.config.Property;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
@Mod(name = "BuildCraft Builders", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Builders", dependencies = DefaultProps.DEPENDENCY_CORE) @Mod(name = "BuildCraft Builders", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Builders", dependencies = DefaultProps.DEPENDENCY_CORE)
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerBuilders.class, clientSideRequired = true, serverSideRequired = true) public class BuildCraftBuilders extends BuildCraftMod {
public class BuildCraftBuilders {
public static final int LIBRARY_PAGE_SIZE = 12; public static final int LIBRARY_PAGE_SIZE = 12;
public static final int MAX_BLUEPRINTS_NAME_SIZE = 14; public static final int MAX_BLUEPRINTS_NAME_SIZE = 14;
@ -118,8 +120,11 @@ public class BuildCraftBuilders {
@EventHandler @EventHandler
public void init(FMLInitializationEvent evt) { public void init(FMLInitializationEvent evt) {
channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-BUILDERS", new PacketHandlerBuilders());
// Register gui handler // Register gui handler
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
// Register save handler // Register save handler
MinecraftForge.EVENT_BUS.register(new EventHandlerBuilders()); MinecraftForge.EVENT_BUS.register(new EventHandlerBuilders());

View file

@ -8,15 +8,21 @@
package buildcraft; package buildcraft;
import static buildcraft.BuildCraftEnergy.spawnOilSprings; import static buildcraft.BuildCraftEnergy.spawnOilSprings;
import java.io.File; import java.io.File;
import java.util.EnumMap;
import java.util.TreeMap; import java.util.TreeMap;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFluid; import net.minecraft.block.BlockFluid;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.IPlantable; import net.minecraftforge.common.IPlantable;
@ -47,6 +53,7 @@ import buildcraft.core.SpringPopulate;
import buildcraft.core.TickHandlerCoreClient; import buildcraft.core.TickHandlerCoreClient;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.core.blueprints.BptItem; import buildcraft.core.blueprints.BptItem;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.EntityIds; import buildcraft.core.network.EntityIds;
import buildcraft.core.network.PacketHandler; import buildcraft.core.network.PacketHandler;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
@ -76,7 +83,8 @@ import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.common.registry.TickRegistry;
@ -84,11 +92,8 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.6.4,1.7)", dependencies = "required-after:Forge@[9.11.1.953,)") @Mod(name = "BuildCraft", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Core", acceptedMinecraftVersions = "[1.6.4,1.7)", dependencies = "required-after:Forge@[9.11.1.953,)")
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandler.class, clientSideRequired = true, serverSideRequired = true) public class BuildCraftCore extends BuildCraftMod {
public class BuildCraftCore {
public static enum RenderMode { public static enum RenderMode {
Full, NoDynamic Full, NoDynamic
}; };
public static RenderMode render = RenderMode.Full; public static RenderMode render = RenderMode.Full;
@ -264,7 +269,9 @@ public class BuildCraftCore {
@EventHandler @EventHandler
public void initialize(FMLInitializationEvent evt) { public void initialize(FMLInitializationEvent evt) {
// MinecraftForge.registerConnectionHandler(new ConnectionHandler()); channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-CORE", new PacketHandler());
ActionManager.registerTriggerProvider(new DefaultTriggerProvider()); ActionManager.registerTriggerProvider(new DefaultTriggerProvider());
ActionManager.registerActionProvider(new DefaultActionProvider()); ActionManager.registerActionProvider(new DefaultActionProvider());

View file

@ -62,8 +62,7 @@ import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
@Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE) @Mod(name = "BuildCraft Energy", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Energy", dependencies = DefaultProps.DEPENDENCY_CORE)
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, clientSideRequired = true, serverSideRequired = true) public class BuildCraftEnergy extends BuildCraftMod {
public class BuildCraftEnergy {
public final static int ENERGY_REMOVE_BLOCK = 25; public final static int ENERGY_REMOVE_BLOCK = 25;
public final static int ENERGY_EXTRACT_ITEM = 2; public final static int ENERGY_EXTRACT_ITEM = 2;
@ -222,7 +221,7 @@ public class BuildCraftEnergy {
@EventHandler @EventHandler
public void init(FMLInitializationEvent evt) { public void init(FMLInitializationEvent evt) {
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
new BptBlockEngine(engineBlock.blockID); new BptBlockEngine(engineBlock.blockID);

View file

@ -10,6 +10,7 @@ package buildcraft;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.InterModComms; import buildcraft.core.InterModComms;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.ConfigUtils; import buildcraft.core.utils.ConfigUtils;
import buildcraft.factory.BlockAutoWorkbench; import buildcraft.factory.BlockAutoWorkbench;
@ -39,7 +40,9 @@ import buildcraft.factory.TileQuarry;
import buildcraft.factory.TileRefinery; import buildcraft.factory.TileRefinery;
import buildcraft.factory.TileTank; import buildcraft.factory.TileTank;
import buildcraft.factory.network.PacketHandlerFactory; import buildcraft.factory.network.PacketHandlerFactory;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Instance;
@ -51,7 +54,9 @@ import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import java.util.List; import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -66,8 +71,7 @@ import net.minecraftforge.common.config.Property;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
@Mod(name = "BuildCraft Factory", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE) @Mod(name = "BuildCraft Factory", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Factory", dependencies = DefaultProps.DEPENDENCY_CORE)
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerFactory.class, clientSideRequired = true, serverSideRequired = true) public class BuildCraftFactory extends BuildCraftMod {
public class BuildCraftFactory {
public static final int MINING_MJ_COST_PER_BLOCK = 64; public static final int MINING_MJ_COST_PER_BLOCK = 64;
public static BlockQuarry quarryBlock; public static BlockQuarry quarryBlock;
@ -127,7 +131,7 @@ public class BuildCraftFactory {
@EventHandler @EventHandler
public void load(FMLInitializationEvent evt) { public void load(FMLInitializationEvent evt) {
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
// EntityRegistry.registerModEntity(EntityMechanicalArm.class, "bcMechanicalArm", EntityIds.MECHANICAL_ARM, instance, 50, 1, true); // EntityRegistry.registerModEntity(EntityMechanicalArm.class, "bcMechanicalArm", EntityIds.MECHANICAL_ARM, instance, 50, 1, true);
@ -154,6 +158,9 @@ public class BuildCraftFactory {
@EventHandler @EventHandler
public void initialize(FMLPreInitializationEvent evt) { public void initialize(FMLPreInitializationEvent evt) {
channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-FACTORY", new PacketHandlerFactory());
ConfigUtils genCat = new ConfigUtils(BuildCraftCore.mainConfiguration, Configuration.CATEGORY_GENERAL); ConfigUtils genCat = new ConfigUtils(BuildCraftCore.mainConfiguration, Configuration.CATEGORY_GENERAL);
allowMining = genCat.get("mining.enabled", true, "disables the recipes for automated mining machines"); allowMining = genCat.get("mining.enabled", true, "disables the recipes for automated mining machines");

View file

@ -0,0 +1,34 @@
package buildcraft;
import java.util.EnumMap;
import cpw.mods.fml.common.network.FMLEmbeddedChannel;
import cpw.mods.fml.common.network.FMLOutboundHandler;
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
import net.minecraft.world.World;
import buildcraft.core.network.BuildCraftPacket;
public class BuildCraftMod {
public EnumMap<Side, FMLEmbeddedChannel> channels;
public void sendToPlayers(BuildCraftPacket packet, World world, int x, int y, int z, int maxDistance) {
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALL);
channels.get(Side.SERVER).writeOutbound(packet);
}
public void sendToPlayer(EntityPlayer entityplayer, BuildCraftPacket packet) {
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER);
channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityplayer);
channels.get(Side.SERVER).writeOutbound(packet);
}
public void sendToServer(BuildCraftPacket packet) {
channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER);
channels.get(Side.CLIENT).writeOutbound(packet);
}
}

View file

@ -16,6 +16,7 @@ import buildcraft.core.InterModComms;
import buildcraft.silicon.ItemRedstoneChipset; import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.ItemRedstoneChipset.Chipset; import buildcraft.silicon.ItemRedstoneChipset.Chipset;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.silicon.BlockLaser; import buildcraft.silicon.BlockLaser;
import buildcraft.silicon.BlockLaserTable; import buildcraft.silicon.BlockLaserTable;
@ -44,17 +45,18 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.config.Property; import net.minecraftforge.common.config.Property;
@Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT) @Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT)
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerSilicon.class, clientSideRequired = true, serverSideRequired = true) public class BuildCraftSilicon extends BuildCraftMod {
public class BuildCraftSilicon {
public static ItemRedstoneChipset redstoneChipset; public static ItemRedstoneChipset redstoneChipset;
public static BlockLaser laserBlock; public static BlockLaser laserBlock;
@ -91,7 +93,10 @@ public class BuildCraftSilicon {
@EventHandler @EventHandler
public void init(FMLInitializationEvent evt) { public void init(FMLInitializationEvent evt) {
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-SILICON", new PacketHandlerSilicon());
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser"); CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser");
CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable"); CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable");
CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench"); CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench");

View file

@ -16,6 +16,7 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.InterModComms; import buildcraft.core.InterModComms;
import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemBuildCraft;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger; import buildcraft.core.triggers.BCTrigger;
@ -101,7 +102,9 @@ import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import java.util.LinkedList; import java.util.LinkedList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
@ -113,7 +116,7 @@ import net.minecraftforge.common.config.Property;
@Mod(version = Version.VERSION, modid = "BuildCraft|Transport", name = "Buildcraft Transport", dependencies = DefaultProps.DEPENDENCY_CORE) @Mod(version = Version.VERSION, modid = "BuildCraft|Transport", name = "Buildcraft Transport", dependencies = DefaultProps.DEPENDENCY_CORE)
@NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerTransport.class, connectionHandler = TransportConnectionHandler.class) @NetworkMod(channels = {DefaultProps.NET_CHANNEL_NAME}, packetHandler = PacketHandlerTransport.class, connectionHandler = TransportConnectionHandler.class)
public class BuildCraftTransport { public class BuildCraftTransport extends BuildCraftMod {
public static BlockGenericPipe genericPipeBlock; public static BlockGenericPipe genericPipeBlock;
public static float pipeDurability; public static float pipeDurability;
@ -344,6 +347,9 @@ public class BuildCraftTransport {
@EventHandler @EventHandler
public void init(FMLInitializationEvent evt) { public void init(FMLInitializationEvent evt) {
channels = NetworkRegistry.INSTANCE.newChannel
(DefaultProps.NET_CHANNEL_NAME + "-TRANSPORT", new PacketHandlerTransport());
// Register connection handler // Register connection handler
// MinecraftForge.registerConnectionHandler(new ConnectionHandler()); // MinecraftForge.registerConnectionHandler(new ConnectionHandler());
@ -377,7 +383,7 @@ public class BuildCraftTransport {
} }
TransportProxy.proxy.registerRenderers(); TransportProxy.proxy.registerRenderers();
NetworkRegistry.instance().registerGuiHandler(instance, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
} }
@EventHandler @EventHandler

View file

@ -2,41 +2,50 @@ package buildcraft.builders.network;
import buildcraft.builders.TileArchitect; import buildcraft.builders.TileArchitect;
import buildcraft.builders.TileBlueprintLibrary; import buildcraft.builders.TileBlueprintLibrary;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayloadArrays; import buildcraft.core.network.PacketPayloadArrays;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.network.Player;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetHandler;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
public class PacketHandlerBuilders implements IPacketHandler { public class PacketHandlerBuilders extends BuildCraftChannelHandler {
@Override @Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
try { try {
int packetID = data.read(); INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player =
CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) { switch (packetID) {
case PacketIds.ARCHITECT_NAME: case PacketIds.ARCHITECT_NAME:
PacketUpdate packetA = new PacketUpdate(); onArchitectName(player, (PacketUpdate) packet);
packetA.readData(data);
onArchitectName((EntityPlayer) player, packetA);
break; break;
case PacketIds.LIBRARY_ACTION: case PacketIds.LIBRARY_ACTION:
PacketLibraryAction packetB = new PacketLibraryAction(); onLibraryAction(player, (PacketLibraryAction) packet);
packetB.readData(data);
onLibraryAction((EntityPlayer) player, packetB);
break; break;
case PacketIds.LIBRARY_SELECT: case PacketIds.LIBRARY_SELECT:
PacketLibraryAction packetC = new PacketLibraryAction(); onLibrarySelect(player, (PacketLibraryAction) packet);
packetC.readData(data);
onLibrarySelect((EntityPlayer) player, packetC);
break; break;
} }
} catch (Exception ex) { } catch (Exception ex) {

View file

@ -1,6 +1,8 @@
package buildcraft.builders.network; package buildcraft.builders.network;
import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketCoordinates;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -17,13 +19,13 @@ public class PacketLibraryAction extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(actionId); data.writeInt(actionId);
super.writeData(data); super.writeData(data);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
actionId = data.readInt(); actionId = data.readInt();
super.readData(data); super.readData(data);
} }

View file

@ -23,7 +23,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -0,0 +1,21 @@
package buildcraft.core.network;
import cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
public class BuildCraftChannelHandler extends FMLIndexedMessageToMessageCodec<BuildCraftPacket> {
public BuildCraftChannelHandler() {
}
@Override
public void encodeInto(ChannelHandlerContext ctx, BuildCraftPacket packet, ByteBuf data) throws Exception {
packet.writeData(data);
}
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
packet.readData(data);
}
}

View file

@ -1,39 +1,15 @@
package buildcraft.core.network; package buildcraft.core.network;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import java.io.ByteArrayOutputStream; import io.netty.buffer.ByteBuf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet250CustomPayload;
public abstract class BuildCraftPacket { public abstract class BuildCraftPacket {
protected boolean isChunkDataPacket = false; protected boolean isChunkDataPacket = false;
protected String channel = DefaultProps.NET_CHANNEL_NAME;
public abstract int getID(); public abstract int getID();
public Packet getPacket() { public abstract void readData(ByteBuf data);
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); public abstract void writeData(ByteBuf data);
DataOutputStream data = new DataOutputStream(bytes);
try {
data.writeByte(getID());
writeData(data);
} catch (IOException e) {
e.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = channel;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
packet.isChunkDataPacket = this.isChunkDataPacket;
return packet;
}
public abstract void readData(DataInputStream data) throws IOException;
public abstract void writeData(DataOutputStream data) throws IOException;
} }

View file

@ -8,7 +8,7 @@
package buildcraft.core.network; package buildcraft.core.network;
import java.io.IOException; import java.io.IOException;
import net.minecraft.network.packet.Packet; import net.minecraft.network.Packet;
public interface ISynchronizedTile { public interface ISynchronizedTile {

View file

@ -1,5 +1,7 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -25,7 +27,7 @@ public class PacketCoordinates extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(posX); data.writeInt(posX);
data.writeInt(posY); data.writeInt(posY);
@ -33,7 +35,7 @@ public class PacketCoordinates extends BuildCraftPacket {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
posX = data.readInt(); posX = data.readInt();
posY = data.readInt(); posY = data.readInt();

View file

@ -1,5 +1,7 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -35,7 +37,7 @@ public class PacketGuiReturn extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(obj.getWorld().provider.dimensionId); data.writeInt(obj.getWorld().provider.dimensionId);
if (obj instanceof TileEntity) { if (obj instanceof TileEntity) {
TileEntity tile = (TileEntity) obj; TileEntity tile = (TileEntity) obj;
@ -55,7 +57,7 @@ public class PacketGuiReturn extends BuildCraftPacket {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
int dim = data.readInt(); int dim = data.readInt();
World world = DimensionManager.getWorld(dim); World world = DimensionManager.getWorld(dim);
boolean tileReturn = data.readBoolean(); boolean tileReturn = data.readBoolean();

View file

@ -10,9 +10,12 @@ package buildcraft.core.network;
import buildcraft.core.gui.BuildCraftContainer; import buildcraft.core.gui.BuildCraftContainer;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.client.entity.EntityClientPlayerMP; import net.minecraft.client.entity.EntityClientPlayerMP;
/** /**
* *
@ -34,14 +37,14 @@ public class PacketGuiWidget extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeByte(windowId); data.writeByte(windowId);
data.writeByte(widgetId); data.writeByte(widgetId);
data.write(payload); data.write(payload);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
windowId = data.readByte(); windowId = data.readByte();
widgetId = data.readByte(); widgetId = data.readByte();

View file

@ -1,18 +1,20 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import buildcraft.core.proxy.CoreProxy;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetHandler;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler { public class PacketHandler extends BuildCraftChannelHandler {
private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException { private void onTileUpdate(EntityPlayer player, PacketTileUpdate packet) throws IOException {
World world = player.worldObj; World world = player.worldObj;
@ -30,23 +32,28 @@ public class PacketHandler implements IPacketHandler {
} }
@Override @Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data)); super.decodeInto(ctx, data, packet);
try { try {
int packetID = data.read(); INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player =
CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) { switch (packetID) {
case PacketIds.TILE_UPDATE: { case PacketIds.TILE_UPDATE: {
PacketTileUpdate pkt = new PacketTileUpdate(); onTileUpdate(player, (PacketTileUpdate) packet);
pkt.readData(data);
onTileUpdate((EntityPlayer) player, pkt);
break; break;
} }
case PacketIds.STATE_UPDATE: { case PacketIds.STATE_UPDATE: {
PacketTileState pkt = new PacketTileState(); PacketTileState pkt = (PacketTileState) packet;
pkt.readData(data); pkt.readData(data);
World world = ((EntityPlayer) player).worldObj; World world = player.worldObj;
TileEntity tile = world.getBlockTileEntity(pkt.posX, pkt.posY, pkt.posZ); TileEntity tile = world.getBlockTileEntity(pkt.posX, pkt.posY, pkt.posZ);
if (tile instanceof ISyncedTile) { if (tile instanceof ISyncedTile) {
pkt.applyStates(data, (ISyncedTile) tile); pkt.applyStates(data, (ISyncedTile) tile);
@ -55,14 +62,12 @@ public class PacketHandler implements IPacketHandler {
} }
case PacketIds.GUI_RETURN: { case PacketIds.GUI_RETURN: {
PacketGuiReturn pkt = new PacketGuiReturn((EntityPlayer) player); // action will have happened already at read time
pkt.readData(data);
break; break;
} }
case PacketIds.GUI_WIDGET: { case PacketIds.GUI_WIDGET: {
PacketGuiWidget pkt = new PacketGuiWidget(); // action will have happened already at read time
pkt.readData(data);
break; break;
} }
} }

View file

@ -1,8 +1,11 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -19,7 +22,7 @@ public class PacketNBT extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
super.writeData(data); super.writeData(data);
@ -29,7 +32,7 @@ public class PacketNBT extends PacketCoordinates {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
super.readData(data); super.readData(data);

View file

@ -2,6 +2,8 @@ package buildcraft.core.network;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -21,9 +23,9 @@ public abstract class PacketPayload {
return null; return null;
} }
public abstract void writeData(DataOutputStream data) throws IOException; public abstract void writeData(ByteBuf data);
public abstract void readData(DataInputStream data) throws IOException; public abstract void readData(ByteBuf data);
public abstract Type getType(); public abstract Type getType();
} }

View file

@ -9,6 +9,8 @@
package buildcraft.core.network; package buildcraft.core.network;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -71,7 +73,7 @@ public class PacketPayloadArrays extends PacketPayload {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(intPayload.length); data.writeInt(intPayload.length);
data.writeInt(floatPayload.length); data.writeInt(floatPayload.length);
data.writeInt(stringPayload.length); data.writeInt(stringPayload.length);
@ -83,12 +85,12 @@ public class PacketPayloadArrays extends PacketPayload {
data.writeFloat(floatData); data.writeFloat(floatData);
} }
for (String stringData : stringPayload) { for (String stringData : stringPayload) {
data.writeUTF(stringData); Utils.writeUTF(data, stringData);
} }
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
intPayload = new int[data.readInt()]; intPayload = new int[data.readInt()];
floatPayload = new float[data.readInt()]; floatPayload = new float[data.readInt()];
stringPayload = new String[data.readInt()]; stringPayload = new String[data.readInt()];
@ -100,7 +102,7 @@ public class PacketPayloadArrays extends PacketPayload {
floatPayload[i] = data.readFloat(); floatPayload[i] = data.readFloat();
} }
for (int i = 0; i < stringPayload.length; i++) { for (int i = 0; i < stringPayload.length; i++) {
stringPayload[i] = data.readUTF(); stringPayload[i] = Utils.readUTF(data);
} }
} }

View file

@ -8,6 +8,8 @@
*/ */
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -25,10 +27,10 @@ public class PacketPayloadStream extends PacketPayload {
public static interface StreamWriter { public static interface StreamWriter {
public void writeData(DataOutputStream data) throws IOException; public void writeData(ByteBuf data);
} }
private StreamWriter handler; private StreamWriter handler;
public DataInputStream stream; public ByteBuf stream;
public PacketPayloadStream() { public PacketPayloadStream() {
} }
@ -38,12 +40,12 @@ public class PacketPayloadStream extends PacketPayload {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
handler.writeData(data); handler.writeData(data);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
stream = data; stream = data;
} }

View file

@ -1,8 +1,11 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.CompressedStreamTools;
@ -21,7 +24,7 @@ public class PacketSlotChange extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
super.writeData(data); super.writeData(data);
@ -45,7 +48,7 @@ public class PacketSlotChange extends PacketCoordinates {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
super.readData(data); super.readData(data);

View file

@ -1,5 +1,7 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -43,7 +45,7 @@ public class PacketTileState extends PacketCoordinates {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
super.readData(data); super.readData(data);
} }
@ -61,7 +63,7 @@ public class PacketTileState extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
super.writeData(data); super.writeData(data);
data.writeByte(stateList.size()); data.writeByte(stateList.size());
for (StateWithId stateWithId : stateList) { for (StateWithId stateWithId : stateList) {

View file

@ -1,5 +1,7 @@
package buildcraft.core.network; package buildcraft.core.network;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -36,7 +38,7 @@ public class PacketUpdate extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(posX); data.writeInt(posX);
data.writeInt(posY); data.writeInt(posY);
@ -51,7 +53,7 @@ public class PacketUpdate extends BuildCraftPacket {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
posX = data.readInt(); posX = data.readInt();
posY = data.readInt(); posY = data.readInt();

View file

@ -14,9 +14,11 @@ import buildcraft.core.network.BuildCraftPacket;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -28,7 +30,9 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.network.packet.Packet; import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.ChunkCoordinates;
@ -131,26 +135,6 @@ public class CoreProxy {
//GameRegistry.addShapelessRecipe(result, recipe); //GameRegistry.addShapelessRecipe(result, recipe);
} }
public void sendToPlayers(Packet packet, World world, int x, int y, int z, int maxDistance) {
if (packet != null) {
for (int j = 0; j < world.playerEntities.size(); j++) {
EntityPlayerMP player = (EntityPlayerMP) world.playerEntities.get(j);
if (Math.abs(player.posX - x) <= maxDistance && Math.abs(player.posY - y) <= maxDistance && Math.abs(player.posZ - z) <= maxDistance) {
player.playerNetServerHandler.sendPacketToPlayer(packet);
}
}
}
}
public void sendToPlayer(EntityPlayer entityplayer, BuildCraftPacket packet) {
EntityPlayerMP player = (EntityPlayerMP) entityplayer;
player.playerNetServerHandler.sendPacketToPlayer(packet.getPacket());
}
public void sendToServer(Packet packet) {
}
public int addCustomTexture(String pathToTexture) { public int addCustomTexture(String pathToTexture) {
return 0; return 0;
} }
@ -237,4 +221,15 @@ public class CoreProxy {
public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) { 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); 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.
*
* TODO: This is a bit kludgy, probably better to separate the client and
* server channels instead.
*/
public EntityPlayer getPlayerFromNetHandler (INetHandler hander) {
return ((NetHandlerPlayServer) hander).field_147369_b;
}
} }

View file

@ -26,18 +26,23 @@ import buildcraft.transport.render.TileEntityPickupFX;
import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.common.registry.LanguageRegistry;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet; import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.ChunkCoordinates;
@ -185,4 +190,9 @@ public class CoreProxyClient extends CoreProxy {
} }
return eb; return eb;
} }
@Override
public EntityPlayer getPlayerFromNetHandler (INetHandler hander) {
return Minecraft.getMinecraft().thePlayer;
}
} }

View file

@ -22,7 +22,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet60Explosion; import net.minecraft.network.Packet60Explosion;
import net.minecraft.world.ChunkPosition; import net.minecraft.world.ChunkPosition;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.World; import net.minecraft.world.World;

View file

@ -25,8 +25,11 @@ import buildcraft.core.network.ISynchronizedTile;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.TileEngine; import buildcraft.energy.TileEngine;
import io.netty.buffer.ByteBuf;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -397,4 +400,27 @@ public class Utils {
} }
return slots; return slots;
} }
public static void writeUTF (ByteBuf data, String str) {
try {
byte [] b = str.getBytes("UTF-8");
data.writeInt (b.length);
data.writeBytes(b);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
data.writeInt (0);
}
}
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) {
e.printStackTrace();
return null;
}
}
} }

View file

@ -15,7 +15,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet3Chat; import net.minecraft.network.Packet3Chat;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent; import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;

View file

@ -1,37 +1,45 @@
package buildcraft.factory.network; package buildcraft.factory.network;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadStream; import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.factory.TileRefinery; import buildcraft.factory.TileRefinery;
import cpw.mods.fml.common.network.IPacketHandler; import io.netty.buffer.ByteBuf;
import cpw.mods.fml.common.network.Player; import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetHandler;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
public class PacketHandlerFactory implements IPacketHandler { public class PacketHandlerFactory extends BuildCraftChannelHandler {
@Override @Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
try { try {
int packetID = data.read(); INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
PacketUpdate packetU = new PacketUpdate();
EntityPlayer player =
CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) { switch (packetID) {
case PacketIds.REFINERY_FILTER_SET: case PacketIds.REFINERY_FILTER_SET:
packetU.readData(data); onRefinerySelect(player, (PacketUpdate) packet);
onRefinerySelect((EntityPlayer) player, packetU);
break; break;
} }

View file

@ -1,53 +1,55 @@
package buildcraft.silicon.network; package buildcraft.silicon.network;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketNBT;
import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.silicon.TileAdvancedCraftingTable; import buildcraft.silicon.TileAdvancedCraftingTable;
import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable;
import buildcraft.silicon.TileAssemblyTable.SelectionMessage; import buildcraft.silicon.TileAssemblyTable.SelectionMessage;
import buildcraft.silicon.gui.ContainerAssemblyTable; import buildcraft.silicon.gui.ContainerAssemblyTable;
import cpw.mods.fml.common.network.IPacketHandler; import io.netty.buffer.ByteBuf;
import cpw.mods.fml.common.network.Player; import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetHandler;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
public class PacketHandlerSilicon implements IPacketHandler { public class PacketHandlerSilicon extends BuildCraftChannelHandler {
@Override @Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
super.decodeInto(ctx, data, packet);
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
try { try {
int packetID = data.read(); INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player =
CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = packet.getID();
switch (packetID) { switch (packetID) {
case PacketIds.SELECTION_ASSEMBLY_SEND: case PacketIds.SELECTION_ASSEMBLY_SEND:
PacketNBT packetT = new PacketNBT(); onSelectionUpdate(player, (PacketNBT) packet);
packetT.readData(data);
onSelectionUpdate((EntityPlayer) player, packetT);
break; break;
case PacketIds.SELECTION_ASSEMBLY: case PacketIds.SELECTION_ASSEMBLY:
PacketNBT packetA = new PacketNBT(); onAssemblySelect(player, (PacketNBT) packet);
packetA.readData(data);
onAssemblySelect((EntityPlayer) player, packetA);
break; break;
case PacketIds.SELECTION_ASSEMBLY_GET: case PacketIds.SELECTION_ASSEMBLY_GET:
PacketCoordinates packetC = new PacketCoordinates(); onAssemblyGetSelection(player, (PacketCoordinates) packet);
packetC.readData(data);
onAssemblyGetSelection((EntityPlayer) player, packetC);
break; break;
case PacketIds.ADVANCED_WORKBENCH_SETSLOT: case PacketIds.ADVANCED_WORKBENCH_SETSLOT:
PacketSlotChange packet1 = new PacketSlotChange(); onAdvancedWorkbenchSet(player, (PacketSlotChange) packet);
packet1.readData(data);
onAdvancedWorkbenchSet((EntityPlayer) player, packet1);
break; break;
} }

View file

@ -18,7 +18,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;

View file

@ -38,7 +38,7 @@ import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet; import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;

View file

@ -5,10 +5,13 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.PipeTransportFluids; import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.BitSet; import java.util.BitSet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -37,7 +40,7 @@ public class PacketFluidUpdate extends PacketCoordinates {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
super.readData(data); super.readData(data);
World world = CoreProxy.proxy.getClientWorld(); World world = CoreProxy.proxy.getClientWorld();
@ -82,7 +85,7 @@ public class PacketFluidUpdate extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
super.writeData(data); super.writeData(data);
byte[] dBytes = toByteArray(delta); byte[] dBytes = toByteArray(delta);

View file

@ -3,8 +3,13 @@ package buildcraft.transport.network;
import buildcraft.api.gates.GateExpansions; import buildcraft.api.gates.GateExpansions;
import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.utils.Utils;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -16,22 +21,22 @@ public class PacketGateExpansionMap extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
BiMap<Byte, String> map = GateExpansions.getServerMap(); BiMap<Byte, String> map = GateExpansions.getServerMap();
data.writeByte(map.size()); data.writeByte(map.size());
for (Map.Entry<Byte, String> entry : map.entrySet()) { for (Map.Entry<Byte, String> entry : map.entrySet()) {
data.writeByte(entry.getKey()); data.writeByte(entry.getKey());
data.writeUTF(entry.getValue()); Utils.writeUTF(data, entry.getValue());
} }
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
int numEntries = data.readByte(); int numEntries = data.readByte();
BiMap<Byte, String> map = HashBiMap.create(numEntries); BiMap<Byte, String> map = HashBiMap.create(numEntries);
for (int i = 0; i < numEntries; i++) { for (int i = 0; i < numEntries; i++) {
byte id = data.readByte(); byte id = data.readByte();
String identifier = data.readUTF(); String identifier = Utils.readUTF(data);
map.put(id, identifier); map.put(id, identifier);
} }
GateExpansions.setClientMap(map); GateExpansions.setClientMap(map);

View file

@ -1,115 +1,110 @@
package buildcraft.transport.network; package buildcraft.transport.network;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketSlotChange;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower; import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe; import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.gui.ContainerGateInterface;
import buildcraft.transport.pipes.PipeItemsDiamond; import buildcraft.transport.pipes.PipeItemsDiamond;
import buildcraft.transport.pipes.PipeItemsEmerald; import buildcraft.transport.pipes.PipeItemsEmerald;
import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.Player; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetHandler;
import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
public class PacketHandlerTransport implements IPacketHandler { public class PacketHandlerTransport extends BuildCraftChannelHandler {
/**
* 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.
*/
@Override @Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet2, Player player) { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) {
DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet2.data)); super.decodeInto(ctx, data, packet);
try { try {
// NetClientHandler net = (NetClientHandler) network.getNetHandler(); INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
EntityPlayer player =
CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
int packetID = data.read(); int packetID = packet.getID();
PacketUpdate packet = new PacketUpdate();
switch (packetID) { switch (packetID) {
case PacketIds.PIPE_POWER: case PacketIds.PIPE_POWER:
PacketPowerUpdate packetPower = new PacketPowerUpdate(); onPacketPower(player, (PacketPowerUpdate) packet);
packetPower.readData(data);
onPacketPower((EntityPlayer) player, packetPower);
break; break;
case PacketIds.PIPE_LIQUID: case PacketIds.PIPE_LIQUID:
PacketFluidUpdate packetFluid = new PacketFluidUpdate(); // action will have happened already at read time
packetFluid.readData(data);
break; break;
case PacketIds.PIPE_TRAVELER: { case PacketIds.PIPE_TRAVELER: {
PacketPipeTransportTraveler pkt = new PacketPipeTransportTraveler(); onPipeTravelerUpdate(player, (PacketPipeTransportTraveler) packet);
pkt.readData(data);
onPipeTravelerUpdate((EntityPlayer) player, pkt);
break; break;
} }
case PacketIds.GATE_ACTIONS: case PacketIds.GATE_ACTIONS:
packet.readData(data); onGateActions(player, (PacketUpdate) packet);
onGateActions((EntityPlayer) player, packet);
break; break;
case PacketIds.GATE_TRIGGERS: case PacketIds.GATE_TRIGGERS:
packet.readData(data); onGateTriggers(player, (PacketUpdate) packet);
onGateTriggers((EntityPlayer) player, packet);
break; break;
case PacketIds.GATE_SELECTION: case PacketIds.GATE_SELECTION:
packet.readData(data); onGateSelection(player, (PacketUpdate) packet);
onGateSelection((EntityPlayer) player, packet);
break; break;
case PacketIds.PIPE_ITEMSTACK: { case PacketIds.PIPE_ITEMSTACK: {
PacketPipeTransportItemStack pkt = new PacketPipeTransportItemStack(); // action will have happened already at read time
pkt.readData(data);
break; break;
} }
case PacketIds.PIPE_GATE_EXPANSION_MAP: { case PacketIds.PIPE_GATE_EXPANSION_MAP: {
PacketGateExpansionMap pkt = new PacketGateExpansionMap(); // action will have happened already at read time
pkt.readData(data);
break; break;
} }
/** /**
* SERVER SIDE * * SERVER SIDE *
*/ */
case PacketIds.DIAMOND_PIPE_SELECT: { case PacketIds.DIAMOND_PIPE_SELECT: {
PacketSlotChange packet1 = new PacketSlotChange(); onDiamondPipeSelect((EntityPlayer) player, (PacketSlotChange) packet);
packet1.readData(data);
onDiamondPipeSelect((EntityPlayer) player, packet1);
break; break;
} }
case PacketIds.EMERALD_PIPE_SELECT: { case PacketIds.EMERALD_PIPE_SELECT: {
PacketSlotChange packet1 = new PacketSlotChange(); onEmeraldPipeSelect((EntityPlayer) player, (PacketSlotChange) packet);
packet1.readData(data);
onEmeraldPipeSelect((EntityPlayer) player, packet1);
break; break;
} }
case PacketIds.GATE_REQUEST_INIT: case PacketIds.GATE_REQUEST_INIT:
PacketCoordinates packetU = new PacketCoordinates(); onGateInitRequest((EntityPlayer) player, (PacketCoordinates) packet);
packetU.readData(data);
onGateInitRequest((EntityPlayer) player, packetU);
break; break;
case PacketIds.GATE_REQUEST_SELECTION: case PacketIds.GATE_REQUEST_SELECTION:
PacketCoordinates packetS = new PacketCoordinates(); onGateSelectionRequest((EntityPlayer) player, (PacketCoordinates) packet);
packetS.readData(data);
onGateSelectionRequest((EntityPlayerMP) player, packetS);
break; break;
case PacketIds.GATE_SELECTION_CHANGE: case PacketIds.GATE_SELECTION_CHANGE:
PacketUpdate packet3 = new PacketUpdate(); onGateSelectionChange((EntityPlayer) player, (PacketUpdate) packet);
packet3.readData(data);
onGateSelectionChange((EntityPlayerMP) player, packet3);
break; break;
case PacketIds.PIPE_ITEMSTACK_REQUEST: { case PacketIds.PIPE_ITEMSTACK_REQUEST: {
PacketPipeTransportItemStackRequest pkt = new PacketPipeTransportItemStackRequest(player); // action will have happened already at read time
pkt.readData(data);
break; break;
} }
} }

View file

@ -3,11 +3,14 @@ package buildcraft.transport.network;
import buildcraft.core.network.BuildCraftPacket; import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet; import net.minecraft.network.Packet;
public class PacketPipeTransportItemStack extends BuildCraftPacket { public class PacketPipeTransportItemStack extends BuildCraftPacket {
@ -23,13 +26,13 @@ public class PacketPipeTransportItemStack extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeInt(entityId); data.writeInt(entityId);
Packet.writeItemStack(stack, data); Packet.writeItemStack(stack, data);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
this.entityId = data.readInt(); this.entityId = data.readInt();
stack = Packet.readItemStack(data); stack = Packet.readItemStack(data);
TravelingItem item = TravelingItem.clientCache.get(entityId); TravelingItem item = TravelingItem.clientCache.get(entityId);

View file

@ -5,6 +5,8 @@ import buildcraft.core.network.PacketIds;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;
import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.network.Player;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -23,12 +25,12 @@ public class PacketPipeTransportItemStackRequest extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeShort(travelerID); data.writeShort(travelerID);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
travelerID = data.readShort(); travelerID = data.readShort();
TravelingItem.TravelingItemCache cache = TravelingItem.serverCache; TravelingItem.TravelingItemCache cache = TravelingItem.serverCache;
TravelingItem item = cache.get(travelerID); TravelingItem item = cache.get(travelerID);

View file

@ -4,9 +4,12 @@ import buildcraft.core.network.BuildCraftPacket;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.utils.EnumColor; import buildcraft.core.utils.EnumColor;
import buildcraft.transport.TravelingItem; import buildcraft.transport.TravelingItem;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -35,7 +38,7 @@ public class PacketPipeTransportTraveler extends BuildCraftPacket {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
data.writeFloat((float) item.xCoord); data.writeFloat((float) item.xCoord);
data.writeFloat((float) item.yCoord); data.writeFloat((float) item.yCoord);
data.writeFloat((float) item.zCoord); data.writeFloat((float) item.zCoord);
@ -53,7 +56,7 @@ public class PacketPipeTransportTraveler extends BuildCraftPacket {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
this.itemX = data.readFloat(); this.itemX = data.readFloat();
this.itemY = data.readFloat(); this.itemY = data.readFloat();
this.itemZ = data.readFloat(); this.itemZ = data.readFloat();

View file

@ -2,6 +2,8 @@ package buildcraft.transport.network;
import buildcraft.core.network.PacketCoordinates; import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import io.netty.buffer.ByteBuf;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -19,7 +21,7 @@ public class PacketPowerUpdate extends PacketCoordinates {
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(ByteBuf data) {
displayPower = new short[] { 0, 0, 0, 0, 0, 0 }; displayPower = new short[] { 0, 0, 0, 0, 0, 0 };
super.readData(data); super.readData(data);
overload = data.readBoolean(); overload = data.readBoolean();
@ -29,7 +31,7 @@ public class PacketPowerUpdate extends PacketCoordinates {
} }
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(ByteBuf data) {
super.writeData(data); super.writeData(data);
data.writeBoolean(overload); data.writeBoolean(overload);
for (int i = 0; i < displayPower.length; i++) { for (int i = 0; i < displayPower.length; i++) {

View file

@ -14,7 +14,7 @@ import cpw.mods.fml.common.network.Player;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler; import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler; import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login; import net.minecraft.network.Packet1Login;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
/** /**