mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +00:00
Network stuffs -> 1.7
This commit is contained in:
1 parent
bb98f77de4
commit
8cd760ea06
34 files changed
+527
-595
No files matched your search
@@ -1,187 +0,0 @@
|
||||
package tconstruct.util.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.blocks.logic.SmelteryLogic;
|
||||
import tconstruct.blocks.logic.ToolForgeLogic;
|
||||
import tconstruct.blocks.logic.ToolStationLogic;
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
public class TPacketHandler// implements IPacketHandler
|
||||
{
|
||||
//1.7 uses netty... commenting this out as it might be needed for reference updating to new packets
|
||||
/*
|
||||
@Override
|
||||
public void onPacketData (NetworkManager manager, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
Side side = FMLCommonHandler.instance().getEffectiveSide();
|
||||
|
||||
if (packet.channel.equals("TConstruct"))
|
||||
{
|
||||
if (side == Side.SERVER)
|
||||
handleServerPacket(packet, (EntityPlayerMP) player);
|
||||
else
|
||||
handleClientPacket(packet, (EntityPlayer) player);
|
||||
}
|
||||
}
|
||||
|
||||
void handleClientPacket (Packet250CustomPayload packet, EntityPlayer player)
|
||||
{
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
byte packetID;
|
||||
|
||||
try
|
||||
{
|
||||
packetID = inputStream.readByte();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
TConstruct.logger.warn("Failed at reading client packet for TConstruct.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void handleServerPacket (Packet250CustomPayload packet, EntityPlayerMP player)
|
||||
{
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
|
||||
byte packetID;
|
||||
|
||||
try
|
||||
{
|
||||
packetID = inputStream.readByte();
|
||||
|
||||
if (packetID == 1) //Tool Station
|
||||
{
|
||||
int dimension = inputStream.readInt();
|
||||
World world = DimensionManager.getWorld(dimension);
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
String toolName = inputStream.readUTF();
|
||||
if (te instanceof ToolStationLogic)
|
||||
{
|
||||
((ToolStationLogic) te).setToolname(toolName);
|
||||
}
|
||||
if (te instanceof ToolForgeLogic)
|
||||
{
|
||||
((ToolForgeLogic) te).setToolname(toolName);
|
||||
}
|
||||
}
|
||||
else if (packetID == 2) //Stencil Table
|
||||
{
|
||||
int dimension = inputStream.readInt();
|
||||
World world = DimensionManager.getWorld(dimension);
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
Short itemID = inputStream.readShort();
|
||||
Short itemDamage = inputStream.readShort();
|
||||
if (te instanceof InventoryLogic)
|
||||
{
|
||||
((InventoryLogic) te).setInventorySlotContents(1, new ItemStack(itemID, 1, itemDamage));
|
||||
}
|
||||
}
|
||||
|
||||
else if (packetID == 3) //Armor
|
||||
{
|
||||
//String user = inputStream.readUTF();
|
||||
//EntityPlayer player = TConstruct.playerTracker.getEntityPlayer(user);
|
||||
switch (inputStream.readByte())
|
||||
{
|
||||
case 0:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.inventoryGui, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
case 1:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.armorGuiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
case 2:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.knapsackGuiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (packetID == 10) //Double jump
|
||||
{
|
||||
//String user = inputStream.readUTF();
|
||||
//EntityPlayer player = TConstruct.playerTracker.getEntityPlayer(user);
|
||||
player.fallDistance = 0;
|
||||
}
|
||||
|
||||
else if (packetID == 11) //Smeltery
|
||||
{
|
||||
int dimension = inputStream.readInt();
|
||||
World world = DimensionManager.getWorld(dimension);
|
||||
int x = inputStream.readInt();
|
||||
int y = inputStream.readInt();
|
||||
int z = inputStream.readInt();
|
||||
|
||||
boolean isShiftPressed = inputStream.readBoolean();
|
||||
int fluidID = inputStream.readInt();
|
||||
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
if (te instanceof SmelteryLogic)
|
||||
{
|
||||
FluidStack temp = null;
|
||||
|
||||
for (FluidStack liquid : ((SmelteryLogic) te).moltenMetal)
|
||||
{
|
||||
if (liquid.fluidID == fluidID)
|
||||
{
|
||||
temp = liquid;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp != null)
|
||||
{
|
||||
((SmelteryLogic) te).moltenMetal.remove(temp);
|
||||
if (isShiftPressed)
|
||||
((SmelteryLogic) te).moltenMetal.add(temp);
|
||||
else
|
||||
((SmelteryLogic) te).moltenMetal.add(0, temp);
|
||||
}
|
||||
PacketDispatcher.sendPacketToAllInDimension(te.getDescriptionPacket(), dimension);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
TConstruct.logger.warn("Failed at reading server packet for TConstruct.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Entity getEntity (World world, int id)
|
||||
{
|
||||
for (Object o : world.loadedEntityList)
|
||||
{
|
||||
if (((Entity) o).entityId == id)
|
||||
return (Entity) o;
|
||||
}
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package tconstruct.util.network.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketDoubleJump extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
//String user = inputStream.readUTF();
|
||||
//EntityPlayer player = TConstruct.playerTracker.getEntityPlayer(user);
|
||||
player.fallDistance = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package tconstruct.util.network.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import tconstruct.TConstruct;
|
||||
|
||||
public class PacketExtendedInventory extends AbstractPacket {
|
||||
|
||||
byte type;
|
||||
|
||||
public PacketExtendedInventory() {
|
||||
|
||||
}
|
||||
|
||||
public PacketExtendedInventory(byte type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeByte(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
type = buffer.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
//String user = inputStream.readUTF();
|
||||
//EntityPlayer player = TConstruct.playerTracker.getEntityPlayer(user);
|
||||
switch (type) {
|
||||
case 0:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.inventoryGui, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
case 1:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.armorGuiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
case 2:
|
||||
player.openGui(TConstruct.instance, TConstruct.proxy.knapsackGuiID, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -102,8 +102,17 @@ public class PacketPipeline extends MessageToMessageCodec<FMLProxyPacket, Abstra
|
||||
// Method to call from FMLInitializationEvent
|
||||
public void initalise() {
|
||||
this.channels = NetworkRegistry.INSTANCE.newChannel("TConstruct", this);
|
||||
registerPackets();
|
||||
}
|
||||
|
||||
public void registerPackets(){
|
||||
registerPacket(PacketDoubleJump.class);
|
||||
registerPacket(PacketExtendedInventory.class);
|
||||
registerPacket(PacketSmeltery.class);
|
||||
registerPacket(PacketStencilTable.class);
|
||||
registerPacket(PacketToolStation.class);
|
||||
}
|
||||
|
||||
// Method to call from FMLPostInitializationEvent
|
||||
// Ensures that packet discriminators are common between server and client by using logical sorting
|
||||
public void postInitialise() {
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package tconstruct.util.network.packet;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import net.minecraft.network.NetworkManager;
|
||||
|
||||
import tconstruct.TConstruct;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import tconstruct.blocks.logic.SmelteryLogic;
|
||||
|
||||
public class PacketSmeltery extends AbstractPacket {
|
||||
|
||||
int dimension, x, y, z, fluidID;
|
||||
boolean isShiftPressed;
|
||||
|
||||
public PacketSmeltery(){
|
||||
|
||||
}
|
||||
|
||||
public PacketSmeltery(int dimension, int x, int y, int z, boolean isShiftPressed, int fluidID){
|
||||
this.dimension = dimension;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.isShiftPressed = isShiftPressed;
|
||||
this.fluidID = fluidID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeInt(dimension);
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
buffer.writeBoolean(isShiftPressed);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
dimension = buffer.readInt();
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
isShiftPressed = buffer.readBoolean();
|
||||
fluidID = buffer.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
World world = player.worldObj;
|
||||
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
if (te instanceof SmelteryLogic)
|
||||
{
|
||||
FluidStack temp = null;
|
||||
|
||||
for (FluidStack liquid : ((SmelteryLogic) te).moltenMetal)
|
||||
{//TODO update fluid stuffs
|
||||
if (liquid.fluidID == fluidID)
|
||||
{
|
||||
temp = liquid;
|
||||
}
|
||||
}
|
||||
|
||||
if (temp != null)
|
||||
{
|
||||
((SmelteryLogic) te).moltenMetal.remove(temp);
|
||||
if (isShiftPressed)
|
||||
((SmelteryLogic) te).moltenMetal.add(temp);
|
||||
else
|
||||
((SmelteryLogic) te).moltenMetal.add(0, temp);
|
||||
}
|
||||
//TODO check if this works like it should
|
||||
//Old code: PacketDispatcher.sendPacketToAllInDimension(te.func_145844_m(), dimension);
|
||||
FMLCommonHandler.instance().getClientToServerNetworkManager().func_150725_a(te.func_145844_m());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package tconstruct.util.network.packet;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import mantle.blocks.abstracts.InventoryLogic;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PacketStencilTable extends AbstractPacket {
|
||||
|
||||
int x, y, z;
|
||||
ItemStack contents;
|
||||
|
||||
public PacketStencilTable() {
|
||||
|
||||
}
|
||||
|
||||
public PacketStencilTable(int x, int y, int z, ItemStack contents) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
ByteBufUtils.writeItemStack(buffer, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
World world = player.worldObj;
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
if (te instanceof InventoryLogic) {
|
||||
((InventoryLogic) te).setInventorySlotContents(1, contents);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package tconstruct.util.network.packet;
|
||||
|
||||
import mantle.util.network.StringEncoder;
|
||||
|
||||
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -13,22 +12,23 @@ public class PacketToolStation extends AbstractPacket {
|
||||
|
||||
private int x, y, z;
|
||||
private String toolName;
|
||||
|
||||
public PacketToolStation(){}
|
||||
|
||||
public PacketToolStation(int x, int y, int z, String toolName){
|
||||
|
||||
public PacketToolStation() {
|
||||
}
|
||||
|
||||
public PacketToolStation(int x, int y, int z, String toolName) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.toolName = toolName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) {
|
||||
buffer.writeInt(x);
|
||||
buffer.writeInt(y);
|
||||
buffer.writeInt(z);
|
||||
StringEncoder.encodeString(buffer, toolName);
|
||||
ByteBufUtils.writeUTF8String(buffer, toolName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,25 +36,24 @@ public class PacketToolStation extends AbstractPacket {
|
||||
x = buffer.readInt();
|
||||
y = buffer.readInt();
|
||||
z = buffer.readInt();
|
||||
toolName = StringEncoder.decodeString(buffer);
|
||||
toolName = ByteBufUtils.readUTF8String(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClientSide(EntityPlayer player) {}
|
||||
public void handleClientSide(EntityPlayer player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleServerSide(EntityPlayer player) {
|
||||
World world = player.worldObj;
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
World world = player.worldObj;
|
||||
TileEntity te = world.func_147438_o(x, y, z);
|
||||
|
||||
if (te instanceof ToolStationLogic)
|
||||
{
|
||||
((ToolStationLogic) te).setToolname(toolName);
|
||||
}
|
||||
if (te instanceof ToolForgeLogic)
|
||||
{
|
||||
((ToolForgeLogic) te).setToolname(toolName);
|
||||
}
|
||||
if (te instanceof ToolStationLogic) {
|
||||
((ToolStationLogic) te).setToolname(toolName);
|
||||
}
|
||||
if (te instanceof ToolForgeLogic) {
|
||||
((ToolForgeLogic) te).setToolname(toolName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user