use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.
the class TileAssemblyTable method rpcSelectRecipe.
public void rpcSelectRecipe(final String id, final boolean select) {
BuildCraftCore.instance.sendToServer(new PacketCommand(this, "select", new CommandWriter() {
@Override
public void write(ByteBuf data) {
NetworkUtils.writeUTF(data, id);
data.writeBoolean(select);
}
}));
}
use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.
the class ContainerZonePlan method saveArea.
public void saveArea(final int index) {
BuildCraftCore.instance.sendToServer(new PacketCommand(this, "saveArea", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeByte(index);
currentAreaSelection.writeData(data);
}
}));
}
use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.
the class ContainerZonePlan method computeMap.
private void computeMap(int cx, int cz, int width, int height, float blocksPerPixel, EntityPlayer player) {
final byte[] textureData = new byte[width * height];
MapWorld w = BuildCraftRobotics.manager.getWorld(map.getWorld());
int startX = Math.round(cx - width * blocksPerPixel / 2);
int startZ = Math.round(cz - height * blocksPerPixel / 2);
int mapStartX = map.chunkStartX << 4;
int mapStartZ = map.chunkStartZ << 4;
for (int j = 0; j < height; ++j) {
for (int i = 0; i < width; ++i) {
int x = Math.round(startX + i * blocksPerPixel);
int z = Math.round(startZ + j * blocksPerPixel);
int ix = x - mapStartX;
int iz = z - mapStartZ;
if (ix >= 0 && iz >= 0 && ix < TileZonePlan.RESOLUTION && iz < TileZonePlan.RESOLUTION) {
textureData[i + j * width] = (byte) w.getColor(x, z);
}
}
}
final int len = MAX_PACKET_LENGTH;
for (int i = 0; i < textureData.length; i += len) {
final int pos = i;
BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "receiveImage", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeMedium(textureData.length);
data.writeMedium(pos);
data.writeBytes(textureData, pos, Math.min(textureData.length - pos, len));
}
}));
}
}
use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.
the class TileRequester method setRequest.
public void setRequest(final int index, final ItemStack stack) {
if (worldObj.isRemote) {
BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setRequest", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeByte(index);
NetworkUtils.writeStack(data, stack);
}
}));
} else {
requests.setInventorySlotContents(index, stack);
}
}
use of buildcraft.core.lib.network.command.CommandWriter in project BuildCraft by BuildCraft.
the class ContainerRequester method receiveCommand.
@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
if (side.isServer() && "getRequestList".equals(command)) {
final ItemStack[] stacks = new ItemStack[TileRequester.NB_ITEMS];
for (int i = 0; i < TileRequester.NB_ITEMS; ++i) {
stacks[i] = requester.getRequestTemplate(i);
}
BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "receiveRequestList", new CommandWriter() {
@Override
public void write(ByteBuf data) {
for (ItemStack s : stacks) {
NetworkUtils.writeStack(data, s);
}
}
}));
} else if (side.isClient() && "receiveRequestList".equals(command)) {
requests = new ItemStack[TileRequester.NB_ITEMS];
for (int i = 0; i < TileRequester.NB_ITEMS; i++) {
requests[i] = NetworkUtils.readStack(stream);
}
}
}
Aggregations