Add ClientUpdateCommandBlockPacket

This commit is contained in:
Jonas Herzig 2018-07-19 14:08:18 +02:00
parent a111addeb4
commit 8e58a9155d
4 changed files with 95 additions and 1 deletions

View file

@ -26,6 +26,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvancementTabPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCraftingBookDataPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket;
@ -474,7 +475,7 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerOutgoing(0x1F, ClientSelectTradePacket.class);
this.registerOutgoing(0x20, ClientSetBeaconEffectPacket.class);
this.registerOutgoing(0x21, ClientPlayerChangeHeldItemPacket.class);
// FIXME: 22
this.registerOutgoing(0x22, ClientUpdateCommandBlockPacket.class);
// FIXME: 23
this.registerOutgoing(0x24, ClientCreativeInventoryActionPacket.class);
// FIXME: 25

View file

@ -60,6 +60,7 @@ import com.github.steveice10.mc.protocol.data.game.window.property.AnvilProperty
import com.github.steveice10.mc.protocol.data.game.window.property.BrewingStandProperty;
import com.github.steveice10.mc.protocol.data.game.window.property.EnchantmentTableProperty;
import com.github.steveice10.mc.protocol.data.game.window.property.FurnaceProperty;
import com.github.steveice10.mc.protocol.data.game.world.block.CommandBlockMode;
import com.github.steveice10.mc.protocol.data.game.world.particle.ParticleType;
import com.github.steveice10.mc.protocol.data.game.world.WorldBorderAction;
import com.github.steveice10.mc.protocol.data.game.world.WorldType;
@ -577,6 +578,10 @@ public class MagicValues {
register(ClientNotification.THUNDER_STRENGTH, 8);
register(ClientNotification.AFFECTED_BY_ELDER_GUARDIAN, 10);
register(CommandBlockMode.SEQUENCE, 0);
register(CommandBlockMode.AUTO, 1);
register(CommandBlockMode.REDSTONE, 2);
register(DemoMessageValue.WELCOME, 0);
register(DemoMessageValue.MOVEMENT_CONTROLS, 101);
register(DemoMessageValue.JUMP_CONTROL, 102);

View file

@ -0,0 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.world.block;
public enum CommandBlockMode {
SEQUENCE,
AUTO,
REDSTONE;
}

View file

@ -0,0 +1,81 @@
package com.github.steveice10.mc.protocol.packet.ingame.client.window;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.CommandBlockMode;
import com.github.steveice10.mc.protocol.packet.MinecraftPacket;
import com.github.steveice10.mc.protocol.util.NetUtil;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import java.io.IOException;
public class ClientUpdateCommandBlockPacket extends MinecraftPacket {
private Position position;
private String command;
private CommandBlockMode mode;
private boolean doesTrackOutput;
private boolean isConditional;
private boolean isAutomatic;
@SuppressWarnings("unused")
private ClientUpdateCommandBlockPacket() {
}
public ClientUpdateCommandBlockPacket(Position position, String command, CommandBlockMode mode,
boolean doesTrackOutput, boolean isConditional, boolean isAutomatic) {
this.position = position;
this.command = command;
this.mode = mode;
this.doesTrackOutput = doesTrackOutput;
this.isConditional = isConditional;
this.isAutomatic = isAutomatic;
}
public Position getPosition() {
return this.position;
}
public String getCommand() {
return this.command;
}
public CommandBlockMode getMode() {
return this.mode;
}
public boolean isDoesTrackOutput() {
return this.doesTrackOutput;
}
public boolean isConditional() {
return this.isConditional;
}
public boolean isAutomatic() {
return this.isAutomatic;
}
@Override
public void read(NetInput in) throws IOException {
this.position = NetUtil.readPosition(in);
this.command = in.readString();
this.mode = MagicValues.key(CommandBlockMode.class, in.readVarInt());
int flags = in.readUnsignedByte();
this.doesTrackOutput = (flags & 0x01) != 0;
this.isConditional = (flags & 0x02) != 0;
this.isAutomatic = (flags & 0x04) != 0;
}
@Override
public void write(NetOutput out) throws IOException {
NetUtil.writePosition(out, this.position);
out.writeString(this.command);
out.writeVarInt(MagicValues.value(Integer.class, this.mode));
int flags = 0;
if (this.doesTrackOutput) flags |= 0x01;
if (this.isConditional) flags |= 0x02;
if (this.isAutomatic) flags |= 0x04;
out.writeByte(flags);
}
}