use of buildcraft.core.lib.network.command.PacketCommand in project BuildCraft by BuildCraft.
the class TileBlueprintLibrary method update.
@Override
public void update() {
super.update();
if (worldObj.isRemote) {
return;
}
if (progressIn > 0 && progressIn < PROGRESS_TIME) {
progressIn++;
}
if (progressOut > 0 && progressOut < PROGRESS_TIME) {
if (selected != -1) {
progressOut++;
} else {
progressOut = 1;
}
}
// client, and then store it to the client.
if (progressIn == 100 && getStackInSlot(1) == null) {
LibraryTypeHandler handler = findHandler(0, LibraryTypeHandler.HandlerType.STORE);
if (handler == null) {
uploadingPlayer = null;
return;
}
byte[] data = null;
if (handler instanceof LibraryTypeHandlerNBT) {
final NBTTagCompound nbt = new NBTTagCompound();
if (((LibraryTypeHandlerNBT) handler).store(getStackInSlot(0), nbt)) {
data = NBTUtilBC.save(nbt);
}
} else if (handler instanceof LibraryTypeHandlerByteArray) {
data = ((LibraryTypeHandlerByteArray) handler).store(getStackInSlot(0));
}
if (data == null) {
uploadingPlayer = null;
return;
}
setInventorySlotContents(1, getStackInSlot(0));
setInventorySlotContents(0, null);
final byte[] dataOut = data;
final LibraryId id = new LibraryId();
id.name = handler.getName(getStackInSlot(1));
id.extension = handler.getOutputExtension();
if (uploadingPlayer != null) {
BuildCraftCore.instance.sendToPlayer(uploadingPlayer, new PacketCommand(this, "downloadBlueprintToClient", new CommandWriter() {
@Override
public void write(ByteBuf data) {
id.generateUniqueId(dataOut);
id.writeData(data);
NetworkUtils.writeByteArray(data, dataOut);
}
}));
uploadingPlayer = null;
}
}
if (progressOut == 100 && getStackInSlot(3) == null) {
BuildCraftCore.instance.sendToPlayer(downloadingPlayer, new PacketCommand(this, "requestSelectedBlueprint", null));
progressOut = 0;
}
}
use of buildcraft.core.lib.network.command.PacketCommand in project BuildCraft by BuildCraft.
the class ContainerGateInterface method receiveCommand.
@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
if (side.isServer()) {
EntityPlayer player = (EntityPlayer) sender;
if ("initRequest".equals(command)) {
final String[] triggerStrings = statementsToStrings(potentialTriggers);
final String[] actionStrings = statementsToStrings(potentialActions);
BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "init", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeByte(gate.getDirection().ordinal());
data.writeShort(triggerStrings.length);
data.writeShort(actionStrings.length);
for (String trigger : triggerStrings) {
NetworkUtils.writeUTF(data, trigger);
}
for (String action : actionStrings) {
NetworkUtils.writeUTF(data, action);
}
}
}));
} else if ("selectionRequest".equals(command)) {
for (int position = 0; position < gate.material.numSlots; position++) {
IStatement action = gate.getAction(position);
IStatement trigger = gate.getTrigger(position);
BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setAction", position, action));
BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setTrigger", position, trigger));
for (int p = 0; p < gate.material.numActionParameters; ++p) {
BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setActionParameter", position, p, gate.getActionParameter(position, p)));
}
for (int q = 0; q < gate.material.numTriggerParameters; ++q) {
BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setTriggerParameter", position, q, gate.getTriggerParameter(position, q)));
}
}
}
} else if (side.isClient()) {
if ("init".equals(command)) {
setGate(stream.readByte());
String[] triggerStrings = new String[stream.readShort()];
String[] actionStrings = new String[stream.readShort()];
for (int i = 0; i < triggerStrings.length; i++) {
triggerStrings[i] = NetworkUtils.readUTF(stream);
}
for (int i = 0; i < actionStrings.length; i++) {
actionStrings[i] = NetworkUtils.readUTF(stream);
}
stringsToStatements(this.potentialTriggers, triggerStrings);
stringsToStatements(this.potentialActions, actionStrings);
}
}
if ("setAction".equals(command)) {
setAction(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
} else if ("setTrigger".equals(command)) {
setTrigger(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
} else if ("setActionParameter".equals(command) || "setTriggerParameter".equals(command)) {
int slot = stream.readUnsignedByte();
int param = stream.readUnsignedByte();
String parameterName = NetworkUtils.readUTF(stream);
NBTTagCompound parameterData = NetworkUtils.readNBT(stream);
IStatementParameter parameter = null;
if (parameterName != null && parameterName.length() > 0) {
parameter = StatementManager.createParameter(parameterName);
}
if (parameter != null) {
parameter.readFromNBT(parameterData);
if ("setActionParameter".equals(command)) {
setActionParameter(slot, param, parameter, false);
} else {
setTriggerParameter(slot, param, parameter, false);
}
}
}
}
use of buildcraft.core.lib.network.command.PacketCommand in project BuildCraft by BuildCraft.
the class EntityRobot method updateClientSlot.
public void updateClientSlot(final int slot) {
BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "clientSetInventory", new CommandWriter() {
@Override
public void write(ByteBuf data) {
data.writeShort(slot);
NetworkUtils.writeStack(data, inv[slot]);
}
}), this);
}
use of buildcraft.core.lib.network.command.PacketCommand in project BuildCraft by BuildCraft.
the class TileZonePlan method importMap.
private void importMap(ItemStack stack) {
if (stack != null && stack.getItem() instanceof IMapLocation) {
final IZone zone = ((IMapLocation) stack.getItem()).getZone(stack);
if (zone != null && zone instanceof ZonePlan) {
selectedAreas[currentSelectedArea] = (ZonePlan) zone;
for (EntityPlayerMP e : MinecraftServer.getServer().getConfigurationManager().playerEntityList) {
if (e.openContainer != null && e.openContainer instanceof ContainerZonePlan && ((ContainerZonePlan) e.openContainer).getTile() == this) {
Packet p = new PacketCommand(e.openContainer, "areaLoaded", new CommandWriter() {
@Override
public void write(ByteBuf data) {
((ZonePlan) zone).writeData(data);
}
});
BuildCraftCore.instance.sendToPlayer(e, p);
}
}
}
}
}
use of buildcraft.core.lib.network.command.PacketCommand in project BuildCraft by BuildCraft.
the class ContainerZonePlan method receiveCommand.
@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
if (side.isClient()) {
if ("areaLoaded".equals(command)) {
currentAreaSelection = new ZonePlan();
currentAreaSelection.readData(stream);
gui.refreshSelectedArea();
} else if ("receiveImage".equals(command)) {
int size = stream.readUnsignedMedium();
int pos = stream.readUnsignedMedium();
for (int i = 0; i < Math.min(size - pos, MAX_PACKET_LENGTH); ++i) {
mapTexture.colorMap[pos + i] = 0xFF000000 | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue;
}
}
} else if (side.isServer()) {
if ("loadArea".equals(command)) {
final int index = stream.readUnsignedByte();
BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender, new PacketCommand(this, "areaLoaded", new CommandWriter() {
@Override
public void write(ByteBuf data) {
map.selectArea(index).writeData(data);
}
}));
} else if ("saveArea".equals(command)) {
final int index = stream.readUnsignedByte();
ZonePlan plan = new ZonePlan();
plan.readData(stream);
map.setArea(index, plan);
} else if ("computeMap".equals(command)) {
computeMap(stream.readInt(), stream.readInt(), stream.readUnsignedShort(), stream.readUnsignedShort(), stream.readFloat(), (EntityPlayer) sender);
} else if ("setName".equals(command)) {
map.mapName = NetworkUtils.readUTF(stream);
}
}
}
Aggregations