library is now passing directly byte arrays over the network, for #1477
This commit is contained in:
parent
c8ebad37c3
commit
aaecf6126a
3 changed files with 39 additions and 29 deletions
|
@ -8,11 +8,13 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.builders;
|
package buildcraft.builders;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.builders.blueprints.BlueprintId;
|
import buildcraft.builders.blueprints.BlueprintId;
|
||||||
|
@ -216,9 +218,8 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
|
||||||
BlueprintBase bpt = ItemBlueprint.getBlueprint(stack [1]);
|
BlueprintBase bpt = ItemBlueprint.getBlueprint(stack [1]);
|
||||||
|
|
||||||
if (bpt != null && uploadingPlayer != null) {
|
if (bpt != null && uploadingPlayer != null) {
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
RPCHandler.rpcPlayer(this, "downloadBlueprintToClient",
|
||||||
bpt.writeToNBT(nbt);
|
uploadingPlayer, bpt.id, bpt.getData());
|
||||||
RPCHandler.rpcPlayer(this, "downloadBlueprintToClient", uploadingPlayer, bpt.id, nbt);
|
|
||||||
uploadingPlayer = null;
|
uploadingPlayer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,38 +240,50 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
|
||||||
public void requestSelectedBlueprint () {
|
public void requestSelectedBlueprint () {
|
||||||
if (selected > -1 && selected < currentPage.size()) {
|
if (selected > -1 && selected < currentPage.size()) {
|
||||||
BlueprintBase bpt = BuildCraftBuilders.clientDB.get(currentPage.get(selected));
|
BlueprintBase bpt = BuildCraftBuilders.clientDB.get(currentPage.get(selected));
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
|
||||||
bpt.writeToNBT(nbt);
|
|
||||||
|
|
||||||
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id, nbt);
|
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id, bpt.getData());
|
||||||
} else {
|
} else {
|
||||||
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null, null);
|
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RPC (RPCSide.SERVER)
|
@RPC (RPCSide.SERVER)
|
||||||
public void uploadBlueprintToServer (BlueprintId id, NBTTagCompound data) {
|
public void uploadBlueprintToServer (BlueprintId id, byte [] data) {
|
||||||
if (data != null) {
|
try {
|
||||||
BlueprintBase bpt = BlueprintBase.loadBluePrint(data);
|
if (data != null) {
|
||||||
bpt.id = id;
|
NBTTagCompound nbt = CompressedStreamTools.decompress(data);
|
||||||
BuildCraftBuilders.serverDB.add(bpt);
|
BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt);
|
||||||
setInventorySlotContents(3, ItemBlueprint.getBlueprintItem(bpt));
|
bpt.setData(data);
|
||||||
} else {
|
bpt.id = id;
|
||||||
setInventorySlotContents(3, stack [2]);
|
BuildCraftBuilders.serverDB.add(bpt);
|
||||||
|
setInventorySlotContents(3, ItemBlueprint.getBlueprintItem(bpt));
|
||||||
|
} else {
|
||||||
|
setInventorySlotContents(3, stack[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInventorySlotContents(2, null);
|
||||||
|
|
||||||
|
downloadingPlayer = null;
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
setInventorySlotContents(2, null);
|
|
||||||
|
|
||||||
downloadingPlayer = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RPC (RPCSide.CLIENT)
|
@RPC (RPCSide.CLIENT)
|
||||||
public void downloadBlueprintToClient (BlueprintId id, NBTTagCompound data) {
|
public void downloadBlueprintToClient (BlueprintId id, byte [] data) {
|
||||||
BlueprintBase bpt = BlueprintBase.loadBluePrint(data);
|
try {
|
||||||
bpt.id = id;
|
NBTTagCompound nbt = CompressedStreamTools.decompress(data);
|
||||||
|
BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt);
|
||||||
|
bpt.setData(data);
|
||||||
|
bpt.id = id;
|
||||||
|
|
||||||
BuildCraftBuilders.clientDB.add(bpt);
|
BuildCraftBuilders.clientDB.add(bpt);
|
||||||
setCurrentPage(BuildCraftBuilders.clientDB.getPage (pageId));
|
setCurrentPage(BuildCraftBuilders.clientDB.getPage(pageId));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectBlueprint (int index) {
|
public void selectBlueprint (int index) {
|
||||||
|
|
|
@ -163,6 +163,7 @@ public class BlueprintDatabase {
|
||||||
NBTTagCompound nbt = CompressedStreamTools.decompress(data);
|
NBTTagCompound nbt = CompressedStreamTools.decompress(data);
|
||||||
|
|
||||||
BlueprintBase blueprint = BlueprintBase.loadBluePrint(nbt);
|
BlueprintBase blueprint = BlueprintBase.loadBluePrint(nbt);
|
||||||
|
blueprint.setData(data);
|
||||||
blueprint.id = id;
|
blueprint.id = id;
|
||||||
|
|
||||||
loadedBlueprints.put(id, blueprint);
|
loadedBlueprints.put(id, blueprint);
|
||||||
|
|
|
@ -411,9 +411,7 @@ public class ClassMapping extends ClassSerializer {
|
||||||
byte [] arr = (byte []) obj;
|
byte [] arr = (byte []) obj;
|
||||||
data.writeInt (arr.length);
|
data.writeInt (arr.length);
|
||||||
|
|
||||||
for (byte element : arr) {
|
data.writeBytes(arr);
|
||||||
data.writeByte(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -496,9 +494,7 @@ public class ClassMapping extends ClassSerializer {
|
||||||
arr = (byte []) obj;
|
arr = (byte []) obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < arr.length; ++i) {
|
data.readBytes (arr);
|
||||||
arr [i] = data.readByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
obj = arr;
|
obj = arr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue