Generalized packet slicing.
Added texture for zone planner.
This commit is contained in:
parent
e155b9b761
commit
1e04358334
17 changed files with 304 additions and 219 deletions
BIN
buildcraft_resources/assets/buildcraft/textures/blocks/zonePlan_front.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/blocks/zonePlan_front.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 478 B |
BIN
buildcraft_resources/assets/buildcraft/textures/blocks/zonePlan_side.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/blocks/zonePlan_side.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 447 B |
|
@ -34,7 +34,7 @@ import buildcraft.api.gates.TriggerParameterItemStack;
|
|||
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.builders.schematics.SchematicRotateMeta;
|
||||
import buildcraft.commander.BlockMap;
|
||||
import buildcraft.commander.BlockZonePlan;
|
||||
import buildcraft.commander.TileZonePlan;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.InterModComms;
|
||||
|
@ -102,7 +102,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
public static ItemRedstoneBoard redstoneBoard;
|
||||
public static BlockLaser laserBlock;
|
||||
public static BlockLaserTable assemblyTableBlock;
|
||||
public static BlockMap zonePlanBlock;
|
||||
public static BlockZonePlan zonePlanBlock;
|
||||
|
||||
@Mod.Instance("BuildCraft|Silicon")
|
||||
public static BuildCraftSilicon instance;
|
||||
|
@ -134,7 +134,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
assemblyTableBlock = new BlockLaserTable();
|
||||
CoreProxy.proxy.registerBlock(assemblyTableBlock, ItemLaserTable.class);
|
||||
|
||||
zonePlanBlock = new BlockMap();
|
||||
zonePlanBlock = new BlockZonePlan();
|
||||
zonePlanBlock.setBlockName("zonePlan");
|
||||
CoreProxy.proxy.registerBlock(zonePlanBlock);
|
||||
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.commander;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.core.BlockBuildCraft;
|
||||
import buildcraft.core.GuiIds;
|
||||
|
||||
public class BlockMap extends BlockBuildCraft {
|
||||
|
||||
public BlockMap() {
|
||||
super(Material.iron);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileZonePlan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7,
|
||||
float par8, float par9) {
|
||||
|
||||
if (!world.isRemote) {
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.MAP,
|
||||
world, i, j, k);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
85
common/buildcraft/commander/BlockZonePlan.java
Executable file
85
common/buildcraft/commander/BlockZonePlan.java
Executable file
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.commander;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.core.BlockBuildCraft;
|
||||
import buildcraft.core.GuiIds;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class BlockZonePlan extends BlockBuildCraft {
|
||||
|
||||
private IIcon blockTextureSide;
|
||||
private IIcon blockTextureFront;
|
||||
|
||||
public BlockZonePlan() {
|
||||
super(Material.iron);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
|
||||
return new TileZonePlan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7,
|
||||
float par8, float par9) {
|
||||
|
||||
if (!world.isRemote) {
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.MAP,
|
||||
world, i, j, k);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, i, j, k, entityliving, stack);
|
||||
|
||||
ForgeDirection orientation = Utils.get2dOrientation(entityliving);
|
||||
|
||||
world.setBlockMetadataWithNotify(i, j, k, orientation.getOpposite().ordinal(), 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
blockTextureSide = par1IconRegister.registerIcon("buildcraft:zonePlan_side");
|
||||
blockTextureFront = par1IconRegister.registerIcon("buildcraft:zonePlan_front");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(int i, int j) {
|
||||
if (j == 0 && i == 3) {
|
||||
return blockTextureFront;
|
||||
}
|
||||
|
||||
if (i == j) {
|
||||
return blockTextureFront;
|
||||
}
|
||||
|
||||
return blockTextureSide;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ package buildcraft.commander;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
@ -52,6 +53,8 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
|
||||
private float alpha = 0.8F;
|
||||
|
||||
private GuiButton tool;
|
||||
|
||||
private static class AreaSlot extends AdvancedSlot {
|
||||
|
||||
public EnumColor color;
|
||||
|
@ -76,6 +79,8 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
public GuiZonePlan(IInventory inventory, TileZonePlan iZonePlan) {
|
||||
super(new ContainerZonePlan(inventory, iZonePlan), inventory, TMP_TEXTURE);
|
||||
|
||||
getContainer().gui = this;
|
||||
|
||||
xSize = 256;
|
||||
ySize = 220;
|
||||
|
||||
|
@ -90,7 +95,6 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
newSelection = new BCDynamicTexture(1, 1);
|
||||
newSelection.createDynamicTexture();
|
||||
|
||||
|
||||
getContainer().currentAreaSelection = new ZonePlan();
|
||||
|
||||
cx = zonePlan.xCoord;
|
||||
|
@ -109,7 +113,18 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
newSelection.setColor(0, 0, colorSelected.color.getDarkHex(), alpha);
|
||||
|
||||
uploadMap();
|
||||
getContainer().gui = this;
|
||||
getContainer().loadArea(colorSelected.color.ordinal());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int x = (width - xSize) / 2;
|
||||
int y = (height - ySize) / 2;
|
||||
|
||||
tool = new GuiButton(0, x + 5, y + 20, 20, 20, "+");
|
||||
buttonList.add(tool);
|
||||
}
|
||||
|
||||
private void uploadMap() {
|
||||
|
@ -236,6 +251,7 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
super.mouseMovedOrUp(mouseX, mouseY, eventType);
|
||||
|
||||
if (eventType != -1 && inSelection) {
|
||||
boolean val = tool.displayString.equals("+");
|
||||
int blockStartX = cx - mapWidth * zoomLevel / 2;
|
||||
int blockStartZ = cz - mapHeight * zoomLevel / 2;
|
||||
|
||||
|
@ -252,7 +268,7 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
int x = blockStartX + (x1 - mapXMin) * zoomLevel + i;
|
||||
int z = blockStartZ + (y1 - mapYMin) * zoomLevel + j;
|
||||
|
||||
getContainer().currentAreaSelection.set(x, z, true);
|
||||
getContainer().currentAreaSelection.set(x, z, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,4 +367,15 @@ public class GuiZonePlan extends GuiAdvancedInterface {
|
|||
protected ContainerZonePlan getContainer() {
|
||||
return (ContainerZonePlan) super.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
if (button == tool) {
|
||||
if (tool.displayString.equals("+")) {
|
||||
tool.displayString = "-";
|
||||
} else {
|
||||
tool.displayString = "+";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -176,6 +176,14 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
NBTTagCompound invNBT = new NBTTagCompound();
|
||||
inv.writeToNBT(invNBT);
|
||||
nbt.setTag("inv", invNBT);
|
||||
|
||||
for (int i = 0; i < selectedAreas.length; ++i) {
|
||||
if (selectedAreas[i] != null) {
|
||||
NBTTagCompound subNBT = new NBTTagCompound();
|
||||
selectedAreas[i].writeToNBT(subNBT);
|
||||
nbt.setTag("selectedArea[" + i + "]", subNBT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,6 +201,13 @@ public class TileZonePlan extends TileBuildCraft implements IInventory {
|
|||
}
|
||||
|
||||
inv.readFromNBT(nbt.getCompoundTag("inv"));
|
||||
|
||||
for (int i = 0; i < selectedAreas.length; ++i) {
|
||||
if (nbt.hasKey("selectedArea[" + i + "]")) {
|
||||
selectedAreas[i] = new ZonePlan();
|
||||
selectedAreas[i].readFromNBT(nbt.getCompoundTag("selectedArea[" + i + "]"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object selectArea(int index) {
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ZoneChunk {
|
|||
if (fullSet) {
|
||||
property = new BitSet(16 * 16);
|
||||
property.flip(0, 16 * 16 - 1);
|
||||
fullSet = false;
|
||||
} else if (property == null) {
|
||||
// Note - ZonePlan should usually destroy such chunks
|
||||
property = new BitSet(16 * 16);
|
||||
|
|
|
@ -23,8 +23,6 @@ import buildcraft.api.core.NetworkData;
|
|||
|
||||
public class ZonePlan implements IZone {
|
||||
|
||||
// TODO: This can exceed 32k of data. Generalize the slicing code used
|
||||
// in tiles.
|
||||
@NetworkData
|
||||
private HashMap<ChunkIndex, ZoneChunk> chunkMapping = new HashMap<ChunkIndex, ZoneChunk>();
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ public class BuildCraftChannelHandler extends FMLIndexedMessageToMessageCodec<Bu
|
|||
addDiscriminator(14, PacketRPCGui.class);
|
||||
addDiscriminator(15, PacketRPCEntity.class);
|
||||
addDiscriminator(16, PacketRPCStatic.class);
|
||||
addDiscriminator(17, PacketRPCPart.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,14 +8,91 @@
|
|||
*/
|
||||
package buildcraft.core.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public abstract class PacketRPC extends BuildCraftPacket {
|
||||
|
||||
public static HashMap<Integer, ByteBuf> bufferedPackets = new HashMap<Integer, ByteBuf>();
|
||||
public static int GLOBAL_ID = new Random(new Date().getTime()).nextInt();
|
||||
|
||||
protected int id;
|
||||
|
||||
protected ByteBuf contents;
|
||||
|
||||
public PacketRPC() {
|
||||
id = GLOBAL_ID++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getID() {
|
||||
return PacketIds.RPC;
|
||||
}
|
||||
|
||||
public abstract void call(EntityPlayer sender);
|
||||
public void call(EntityPlayer sender) {
|
||||
if (bufferedPackets.containsKey(id)) {
|
||||
ByteBuf data = bufferedPackets.remove(id);
|
||||
|
||||
if (data != null) {
|
||||
contents = data.writeBytes(contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<PacketRPC> breakIntoSmallerPackets(int maxSize) {
|
||||
ArrayList<PacketRPC> messages = new ArrayList<PacketRPC>();
|
||||
|
||||
if (contents.readableBytes() < maxSize) {
|
||||
messages.add(this);
|
||||
return messages;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (true) {
|
||||
ByteBuf subContents = contents.readBytes(contents.readableBytes() > maxSize ? maxSize : contents
|
||||
.readableBytes());
|
||||
|
||||
PacketRPCPart subPacket = new PacketRPCPart();
|
||||
subPacket.id = id;
|
||||
subPacket.contents = subContents;
|
||||
|
||||
messages.add(subPacket);
|
||||
|
||||
start += maxSize;
|
||||
|
||||
if (contents.readableBytes() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
contents = Unpooled.buffer();
|
||||
|
||||
messages.add(this);
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
id = data.readInt();
|
||||
int length = data.readInt();
|
||||
contents = Unpooled.buffer(length);
|
||||
data.readBytes(contents, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
data.writeInt(id);
|
||||
data.writeInt(contents.readableBytes());
|
||||
data.writeBytes(contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,49 +9,47 @@
|
|||
package buildcraft.core.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketRPCEntity extends PacketRPC {
|
||||
private byte[] contents;
|
||||
private Entity entity;
|
||||
private int entityId;
|
||||
|
||||
public PacketRPCEntity() {
|
||||
}
|
||||
|
||||
public PacketRPCEntity(Entity iEntity, byte[] bytes) {
|
||||
public PacketRPCEntity(Entity iEntity, ByteBuf bytes) {
|
||||
entity = iEntity;
|
||||
contents = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(EntityPlayer sender) {
|
||||
super.call(sender);
|
||||
|
||||
RPCMessageInfo info = new RPCMessageInfo();
|
||||
info.sender = sender;
|
||||
|
||||
ByteBuf completeData = Unpooled.buffer();
|
||||
completeData.writeBytes(contents);
|
||||
|
||||
entity = sender.worldObj.getEntityByID(entityId);
|
||||
|
||||
if (entity != null) {
|
||||
RPCHandler.receiveRPC(entity, info, completeData);
|
||||
RPCHandler.receiveRPC(entity, info, contents);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
super.readData(data);
|
||||
|
||||
entityId = data.readInt();
|
||||
contents = new byte[data.readableBytes()];
|
||||
data.readBytes(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeInt(entity.getEntityId());
|
||||
data.writeBytes(contents);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,39 +9,24 @@
|
|||
package buildcraft.core.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketRPCGui extends PacketRPC {
|
||||
byte [] contents;
|
||||
|
||||
public PacketRPCGui() {
|
||||
}
|
||||
|
||||
public PacketRPCGui(byte[] bytes) {
|
||||
public PacketRPCGui(ByteBuf bytes) {
|
||||
contents = bytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
contents = new byte [data.readableBytes()];
|
||||
data.readBytes(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call (EntityPlayer sender) {
|
||||
super.call(sender);
|
||||
|
||||
RPCMessageInfo info = new RPCMessageInfo();
|
||||
info.sender = sender;
|
||||
|
||||
ByteBuf completeData = Unpooled.buffer();
|
||||
completeData.writeBytes(contents);
|
||||
|
||||
RPCHandler.receiveRPC(sender.openContainer, info, completeData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
data.writeBytes(contents);
|
||||
RPCHandler.receiveRPC(sender.openContainer, info, contents);
|
||||
}
|
||||
}
|
||||
|
|
21
common/buildcraft/core/network/PacketRPCPart.java
Executable file
21
common/buildcraft/core/network/PacketRPCPart.java
Executable file
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketRPCPart extends PacketRPC {
|
||||
|
||||
@Override
|
||||
public void call(EntityPlayer sender) {
|
||||
super.call(sender);
|
||||
|
||||
bufferedPackets.put(id, contents);
|
||||
}
|
||||
}
|
|
@ -9,48 +9,46 @@
|
|||
package buildcraft.core.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class PacketRPCStatic extends PacketRPC {
|
||||
private byte[] contents;
|
||||
private String classId;
|
||||
private Class<?> clas;
|
||||
|
||||
public PacketRPCStatic() {
|
||||
}
|
||||
|
||||
public PacketRPCStatic(Class iClass, byte[] bytes) {
|
||||
public PacketRPCStatic(Class iClass, ByteBuf bytes) {
|
||||
contents = bytes;
|
||||
clas = iClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
contents = new byte [data.readableBytes()];
|
||||
data.readBytes(contents);
|
||||
}
|
||||
super.readData(data);
|
||||
|
||||
@Override
|
||||
public void call (EntityPlayer sender) {
|
||||
RPCMessageInfo info = new RPCMessageInfo();
|
||||
info.sender = sender;
|
||||
|
||||
ByteBuf completeData = Unpooled.buffer();
|
||||
completeData.writeBytes(contents);
|
||||
|
||||
String classId = NetworkIdRegistry.read(completeData);
|
||||
|
||||
try {
|
||||
RPCHandler.receiveStaticRPC(Class.forName(classId), info, completeData);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
classId = NetworkIdRegistry.read(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
super.writeData(data);
|
||||
|
||||
NetworkIdRegistry.write(data, clas.getCanonicalName());
|
||||
data.writeBytes(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call (EntityPlayer sender) {
|
||||
super.call(sender);
|
||||
|
||||
RPCMessageInfo info = new RPCMessageInfo();
|
||||
info.sender = sender;
|
||||
|
||||
try {
|
||||
RPCHandler.receiveStaticRPC(Class.forName(classId), info, contents);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,7 @@
|
|||
*/
|
||||
package buildcraft.core.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -25,22 +17,17 @@ import net.minecraft.world.World;
|
|||
import net.minecraftforge.common.DimensionManager;
|
||||
|
||||
public class PacketRPCTile extends PacketRPC {
|
||||
public static int GLOBAL_ID = new Random(new Date().getTime()).nextInt();
|
||||
public static HashMap<Integer, ByteBuf> bufferedPackets = new HashMap<Integer, ByteBuf>();
|
||||
public TileEntity tile;
|
||||
|
||||
byte [] contents;
|
||||
int id;
|
||||
boolean moreDataToCome = false;
|
||||
public TileEntity tile;
|
||||
|
||||
int dimId;
|
||||
int x, y, z;
|
||||
|
||||
public PacketRPCTile () {
|
||||
id = GLOBAL_ID++;
|
||||
|
||||
}
|
||||
|
||||
public PacketRPCTile(TileEntity tile, byte[] bytes) {
|
||||
public PacketRPCTile(TileEntity tile, ByteBuf bytes) {
|
||||
this.tile = tile;
|
||||
contents = bytes;
|
||||
}
|
||||
|
@ -51,15 +38,24 @@ public class PacketRPCTile extends PacketRPC {
|
|||
|
||||
@Override
|
||||
public void readData(ByteBuf data) {
|
||||
dimId = data.readShort();
|
||||
super.readData(data);
|
||||
|
||||
dimId = data.readShort();
|
||||
x = data.readInt();
|
||||
y = data.readInt();
|
||||
z = data.readInt();
|
||||
id = data.readInt ();
|
||||
moreDataToCome = data.readBoolean();
|
||||
contents = new byte [data.readableBytes()];
|
||||
data.readBytes(contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
super.writeData(data);
|
||||
|
||||
// In order to save space on message, we assuming dimensions ids
|
||||
// small. Maybe worth using a varint instead
|
||||
data.writeShort(tile.getWorldObj().provider.dimensionId);
|
||||
data.writeInt(tile.xCoord);
|
||||
data.writeInt(tile.yCoord);
|
||||
data.writeInt(tile.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,70 +79,6 @@ public class PacketRPCTile extends PacketRPC {
|
|||
RPCMessageInfo info = new RPCMessageInfo();
|
||||
info.sender = sender;
|
||||
|
||||
ByteBuf previousData = bufferedPackets.get(id);
|
||||
bufferedPackets.remove(id);
|
||||
|
||||
ByteBuf completeData;
|
||||
|
||||
if (previousData != null) {
|
||||
completeData = previousData.writeBytes(contents);
|
||||
} else {
|
||||
completeData = Unpooled.buffer();
|
||||
completeData.writeBytes(contents);
|
||||
}
|
||||
|
||||
if (!moreDataToCome) {
|
||||
RPCHandler.receiveRPC(localTile, info, completeData);
|
||||
} else {
|
||||
bufferedPackets.put(id, completeData);
|
||||
}
|
||||
RPCHandler.receiveRPC(localTile, info, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(ByteBuf data) {
|
||||
// In order to save space on message, we assuming dimensions ids
|
||||
// small. Maybe worth using a varint instead
|
||||
data.writeShort(tile.getWorldObj().provider.dimensionId);
|
||||
data.writeInt(tile.xCoord);
|
||||
data.writeInt(tile.yCoord);
|
||||
data.writeInt(tile.zCoord);
|
||||
|
||||
data.writeInt(id);
|
||||
data.writeBoolean(moreDataToCome);
|
||||
data.writeBytes(contents);
|
||||
}
|
||||
|
||||
public ArrayList<PacketRPCTile> breakIntoSmallerPackets(int maxSize) {
|
||||
ArrayList<PacketRPCTile> messages = new ArrayList<PacketRPCTile>();
|
||||
|
||||
if (contents.length < maxSize) {
|
||||
messages.add(this);
|
||||
return messages;
|
||||
}
|
||||
|
||||
int start = 0;
|
||||
|
||||
while (true) {
|
||||
byte [] subContents = ArrayUtils.subarray(contents, start, start + maxSize);
|
||||
|
||||
PacketRPCTile subPacket = new PacketRPCTile();
|
||||
subPacket.id = id;
|
||||
subPacket.contents = subContents;
|
||||
subPacket.tile = tile;
|
||||
|
||||
messages.add(subPacket);
|
||||
|
||||
start += maxSize;
|
||||
|
||||
if (start >= contents.length) {
|
||||
subPacket.moreDataToCome = false;
|
||||
break;
|
||||
} else {
|
||||
subPacket.moreDataToCome = true;
|
||||
}
|
||||
}
|
||||
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -128,29 +128,21 @@ public final class RPCHandler {
|
|||
}
|
||||
|
||||
public static void rpcServer(Object object, String method, Object... actuals) {
|
||||
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||
PacketRPC packet = createPacket(object, method, actuals);
|
||||
|
||||
if (packet != null) {
|
||||
if (packet instanceof PacketRPCTile) {
|
||||
for (PacketRPCTile p : ((PacketRPCTile) packet).breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToServer(p);
|
||||
}
|
||||
} else {
|
||||
BuildCraftCore.instance.sendToServer(packet);
|
||||
for (PacketRPC p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToServer(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void rpcPlayer(EntityPlayer player, Object object, String method, Object... actuals) {
|
||||
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||
PacketRPC packet = createPacket(object, method, actuals);
|
||||
|
||||
if (packet != null) {
|
||||
if (packet instanceof PacketRPCTile) {
|
||||
for (PacketRPCTile p : ((PacketRPCTile) packet).breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToPlayer(player, p);
|
||||
}
|
||||
} else {
|
||||
BuildCraftCore.instance.sendToPlayer(player, packet);
|
||||
for (PacketRPC p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToPlayer(player, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -161,15 +153,13 @@ public final class RPCHandler {
|
|||
|
||||
public static void rpcBroadcastPlayersAtDistance(World world, Object object, String method, int maxDistance,
|
||||
Object... actuals) {
|
||||
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||
PacketRPC packet = createPacket(object, method, actuals);
|
||||
|
||||
if (packet != null) {
|
||||
if (packet instanceof PacketRPCTile) {
|
||||
TileEntity tile = (TileEntity) object;
|
||||
|
||||
for (PacketRPCTile p : ((PacketRPCTile) packet)
|
||||
.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
|
||||
for (PacketRPC p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
for (Object o : world.playerEntities) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||
|
||||
|
@ -184,20 +174,24 @@ public final class RPCHandler {
|
|||
for (Object o : world.playerEntities) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||
|
||||
BuildCraftCore.instance.sendToPlayer(player, packet);
|
||||
for (PacketRPC p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToPlayer(player, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void rpcBroadcastAllPlayers(Object object, String method, Object... actuals) {
|
||||
BuildCraftPacket packet = createPacket(object, method, actuals);
|
||||
PacketRPC packet = createPacket(object, method, actuals);
|
||||
|
||||
if (packet != null) {
|
||||
for (Object o : FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) o;
|
||||
|
||||
BuildCraftCore.instance.sendToPlayer(player, packet);
|
||||
for (PacketRPC p : packet.breakIntoSmallerPackets(MAX_PACKET_SIZE)) {
|
||||
BuildCraftCore.instance.sendToPlayer(player, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,8 +236,8 @@ public final class RPCHandler {
|
|||
return new PacketRPCPipe(bytes);
|
||||
}
|
||||
|
||||
private static BuildCraftPacket createPacket(Object object, String method, Object... actuals) {
|
||||
BuildCraftPacket packet = null;
|
||||
private static PacketRPC createPacket(Object object, String method, Object... actuals) {
|
||||
PacketRPC packet = null;
|
||||
|
||||
if (object instanceof Container) {
|
||||
packet = getHandler(object).createRCPPacketContainer(method, actuals);
|
||||
|
@ -258,7 +252,7 @@ public final class RPCHandler {
|
|||
return packet;
|
||||
}
|
||||
|
||||
private byte[] getBytes(String method, Object... actuals) {
|
||||
private ByteBuf getBytes(String method, Object... actuals) {
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
|
||||
try {
|
||||
|
@ -271,10 +265,7 @@ public final class RPCHandler {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
byte [] bytes = new byte [data.readableBytes()];
|
||||
data.readBytes(bytes);
|
||||
|
||||
return bytes;
|
||||
return data;
|
||||
}
|
||||
|
||||
private PacketRPCTile createRCPPacketTile(TileEntity tile, String method, Object... actuals) {
|
||||
|
@ -289,7 +280,7 @@ public final class RPCHandler {
|
|||
return new PacketRPCEntity(entity, getBytes(method, actuals));
|
||||
}
|
||||
|
||||
private BuildCraftPacket createRCPPacketStatic(Class<?> clas, String method, Object[] actuals) {
|
||||
private PacketRPC createRCPPacketStatic(Class<?> clas, String method, Object[] actuals) {
|
||||
return new PacketRPCStatic(clas, getBytes(method, actuals));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue