From a91a407d90498eb7c161862b7757f7a171680277 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Mon, 24 Aug 2015 20:17:03 -0700 Subject: [PATCH] 15w35b --- .../mc/protocol/MinecraftConstants.java | 4 +- .../mc/protocol/MinecraftProtocol.java | 29 +++--- .../data/game/chunk/BlockStateMap.java | 81 +++++++-------- .../server/ServerSetCooldownPacket.java | 48 +++++++++ .../world/ServerMultiChunkDataPacket.java | 98 ------------------- .../server/world/ServerUnloadChunkPacket.java | 46 +++++++++ 6 files changed, 147 insertions(+), 159 deletions(-) create mode 100644 src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerSetCooldownPacket.java delete mode 100644 src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java create mode 100644 src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerUnloadChunkPacket.java diff --git a/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java b/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java index ea83db3a..346d335f 100644 --- a/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java +++ b/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java @@ -2,8 +2,8 @@ package org.spacehq.mc.protocol; public class MinecraftConstants { // General Constants - public static final String GAME_VERSION = "15w34d"; - public static final int PROTOCOL_VERSION = 61; + public static final String GAME_VERSION = "15w35b"; + public static final int PROTOCOL_VERSION = 63; // General Key Constants public static final String PROFILE_KEY = "profile"; diff --git a/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java b/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java index b25405a4..4f4aed51 100644 --- a/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java +++ b/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java @@ -1,8 +1,8 @@ package org.spacehq.mc.protocol; import org.spacehq.mc.auth.data.GameProfile; -import org.spacehq.mc.auth.service.AuthenticationService; import org.spacehq.mc.auth.exception.request.RequestException; +import org.spacehq.mc.auth.service.AuthenticationService; import org.spacehq.mc.protocol.data.SubProtocol; import org.spacehq.mc.protocol.packet.handshake.client.HandshakePacket; import org.spacehq.mc.protocol.packet.ingame.client.ClientChatPacket; @@ -32,6 +32,7 @@ import org.spacehq.mc.protocol.packet.ingame.client.window.ClientCreativeInvento import org.spacehq.mc.protocol.packet.ingame.client.window.ClientEnchantItemPacket; import org.spacehq.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket; import org.spacehq.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket; +import org.spacehq.mc.protocol.packet.ingame.server.ServerBossBarPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerChatPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerCombatPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerDifficultyPacket; @@ -44,6 +45,7 @@ import org.spacehq.mc.protocol.packet.ingame.server.ServerPluginMessagePacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerResourcePackSendPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerRespawnPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerSetCompressionPacket; +import org.spacehq.mc.protocol.packet.ingame.server.ServerSetCooldownPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerStatisticsPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerSwitchCameraPacket; import org.spacehq.mc.protocol.packet.ingame.server.ServerTabCompletePacket; @@ -57,7 +59,6 @@ import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityEquipment import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket; import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket; import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityMovementPacket; -import org.spacehq.mc.protocol.packet.ingame.server.ServerBossBarPacket; import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket; import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; @@ -95,13 +96,13 @@ import org.spacehq.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerExplosionPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerMapDataPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket; -import org.spacehq.mc.protocol.packet.ingame.server.world.ServerMultiChunkDataPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerOpenTileEntityEditorPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerPlayEffectPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerPlaySoundPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerSpawnParticlePacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerSpawnPositionPacket; +import org.spacehq.mc.protocol.packet.ingame.server.world.ServerUnloadChunkPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerUpdateSignPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket; import org.spacehq.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket; @@ -344,11 +345,11 @@ public class MinecraftProtocol extends PacketProtocol { this.registerIncoming(31, ServerSetExperiencePacket.class); this.registerIncoming(32, ServerEntityPropertiesPacket.class); this.registerIncoming(33, ServerChunkDataPacket.class); - this.registerIncoming(34, ServerMultiBlockChangePacket.class); - this.registerIncoming(35, ServerBlockChangePacket.class); - this.registerIncoming(36, ServerBlockValuePacket.class); - this.registerIncoming(37, ServerBlockBreakAnimPacket.class); - this.registerIncoming(38, ServerMultiChunkDataPacket.class); + this.registerIncoming(34, ServerUnloadChunkPacket.class); + this.registerIncoming(35, ServerMultiBlockChangePacket.class); + this.registerIncoming(36, ServerBlockChangePacket.class); + this.registerIncoming(37, ServerBlockValuePacket.class); + this.registerIncoming(38, ServerBlockBreakAnimPacket.class); this.registerIncoming(39, ServerExplosionPacket.class); this.registerIncoming(40, ServerPlayEffectPacket.class); this.registerIncoming(41, ServerPlaySoundPacket.class); @@ -384,6 +385,7 @@ public class MinecraftProtocol extends PacketProtocol { this.registerIncoming(71, ServerPlayerListDataPacket.class); this.registerIncoming(72, ServerResourcePackSendPacket.class); this.registerIncoming(73, ServerBossBarPacket.class); + this.registerIncoming(74, ServerSetCooldownPacket.class); this.registerOutgoing(0, ClientKeepAlivePacket.class); this.registerOutgoing(1, ClientChatPacket.class); @@ -476,11 +478,11 @@ public class MinecraftProtocol extends PacketProtocol { this.registerOutgoing(31, ServerSetExperiencePacket.class); this.registerOutgoing(32, ServerEntityPropertiesPacket.class); this.registerOutgoing(33, ServerChunkDataPacket.class); - this.registerOutgoing(34, ServerMultiBlockChangePacket.class); - this.registerOutgoing(35, ServerBlockChangePacket.class); - this.registerOutgoing(36, ServerBlockValuePacket.class); - this.registerOutgoing(37, ServerBlockBreakAnimPacket.class); - this.registerOutgoing(38, ServerMultiChunkDataPacket.class); + this.registerOutgoing(34, ServerUnloadChunkPacket.class); + this.registerOutgoing(35, ServerMultiBlockChangePacket.class); + this.registerOutgoing(36, ServerBlockChangePacket.class); + this.registerOutgoing(37, ServerBlockValuePacket.class); + this.registerOutgoing(38, ServerBlockBreakAnimPacket.class); this.registerOutgoing(39, ServerExplosionPacket.class); this.registerOutgoing(40, ServerPlayEffectPacket.class); this.registerOutgoing(41, ServerPlaySoundPacket.class); @@ -516,6 +518,7 @@ public class MinecraftProtocol extends PacketProtocol { this.registerOutgoing(71, ServerPlayerListDataPacket.class); this.registerOutgoing(72, ServerResourcePackSendPacket.class); this.registerOutgoing(73, ServerBossBarPacket.class); + this.registerOutgoing(74, ServerSetCooldownPacket.class); } private void initClientStatus(Session session) { diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/chunk/BlockStateMap.java b/src/main/java/org/spacehq/mc/protocol/data/game/chunk/BlockStateMap.java index d3114020..42e205ff 100644 --- a/src/main/java/org/spacehq/mc/protocol/data/game/chunk/BlockStateMap.java +++ b/src/main/java/org/spacehq/mc/protocol/data/game/chunk/BlockStateMap.java @@ -4,88 +4,77 @@ import org.spacehq.packetlib.io.NetInput; import org.spacehq.packetlib.io.NetOutput; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; public class BlockStateMap { private static final int[] MAX_ID_PER_BYTES = { 15, 255, 4095 }; private BlockStorage parent; - private Map idToState = new HashMap(); - private Map stateToId = new HashMap(); - private int stateCount = 0; - - private int currentSize = 0; + private List states = new ArrayList(); + private int currentMaxValue = 0; public BlockStateMap(BlockStorage parent) { this.parent = parent; - this.idToState.put(0, 0); - this.stateToId.put(0, 0); - this.stateCount++; + this.states.add(0); } public BlockStateMap(BlockStorage parent, NetInput in) throws IOException { - this.parent = parent; - - this.stateCount = in.readVarInt(); - for(int i = 0; i < this.stateCount; i++) { - int state = in.readVarInt(); - int id = in.readVarInt(); - - this.idToState.put(id, state); - this.stateToId.put(state, id); + int stateCount = in.readVarInt(); + for(int i = 0; i < stateCount; i++) { + this.addState(in.readVarInt()); } + + this.parent = parent; } public void write(NetOutput out) throws IOException { - out.writeVarInt(this.stateCount); - for(Map.Entry entry : this.stateToId.entrySet()) { - out.writeVarInt(entry.getKey()); - out.writeVarInt(entry.getValue()); + out.writeVarInt(this.states.size()); + for(int state : this.states) { + out.writeVarInt(state); } } - public Map getIdsToStates() { - return new HashMap(this.idToState); - } - - public Map getStatesToIds() { - return new HashMap(this.stateToId); + public List getStates() { + return new ArrayList(this.states); } public int getState(int id) { - return this.idToState.containsKey(id) ? this.idToState.get(id) : 0; + return id >= 0 && id < this.states.size() ? this.states.get(id) : 0; } public int getId(int state) { - if(!this.stateToId.containsKey(state)) { - int id = this.stateCount; - this.idToState.put(id, state); - this.stateToId.put(state, id); - - if(this.currentSize < MAX_ID_PER_BYTES.length - 1 && this.stateCount > MAX_ID_PER_BYTES[this.currentSize]) { - this.parent.resize(MAX_ID_PER_BYTES[++this.currentSize]); - } - - this.stateCount++; + int id = this.states.indexOf(state); + if(id == -1) { + id = this.addState(state); } - return this.stateToId.get(state); + return id; + } + + private int addState(int state) { + this.states.add(state); + if(this.currentMaxValue < MAX_ID_PER_BYTES.length - 1 && this.states.size() > MAX_ID_PER_BYTES[this.currentMaxValue]) { + this.currentMaxValue++; + if(this.parent != null) { + this.parent.resize(MAX_ID_PER_BYTES[this.currentMaxValue]); + } + } + + return this.states.indexOf(state); } @Override public boolean equals(Object o) { - return this == o || (o instanceof BlockStateMap && this.idToState.equals(((BlockStateMap) o).idToState) && this.stateToId.equals(((BlockStateMap) o).stateToId) && this.stateCount == ((BlockStateMap) o).stateCount && this.currentSize == ((BlockStateMap) o).currentSize); + return this == o || (o instanceof BlockStateMap && this.states.equals(((BlockStateMap) o).states) && this.currentMaxValue == ((BlockStateMap) o).currentMaxValue); } @Override public int hashCode() { - int result = this.idToState.hashCode(); - result = 31 * result + this.stateToId.hashCode(); - result = 31 * result + this.stateCount; - result = 31 * result + this.currentSize; + int result = this.states.hashCode(); + result = 31 * result + this.currentMaxValue; return result; } } diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerSetCooldownPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerSetCooldownPacket.java new file mode 100644 index 00000000..81c9ff31 --- /dev/null +++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerSetCooldownPacket.java @@ -0,0 +1,48 @@ +package org.spacehq.mc.protocol.packet.ingame.server; + +import org.spacehq.packetlib.io.NetInput; +import org.spacehq.packetlib.io.NetOutput; +import org.spacehq.packetlib.packet.Packet; + +import java.io.IOException; + +public class ServerSetCooldownPacket implements Packet { + + private int itemId; + private int cooldownTicks; + + @SuppressWarnings("unused") + private ServerSetCooldownPacket() { + } + + public ServerSetCooldownPacket(int itemId, int cooldownTicks) { + this.itemId = itemId; + this.cooldownTicks = cooldownTicks; + } + + public int getItemId() { + return this.itemId; + } + + public int getCooldownTicks() { + return this.cooldownTicks; + } + + @Override + public void read(NetInput in) throws IOException { + this.itemId = in.readVarInt(); + this.cooldownTicks = in.readVarInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeVarInt(this.itemId); + out.writeVarInt(this.cooldownTicks); + } + + @Override + public boolean isPriority() { + return false; + } + +} diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java deleted file mode 100644 index 646271b2..00000000 --- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerMultiChunkDataPacket.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.spacehq.mc.protocol.packet.ingame.server.world; - -import org.spacehq.mc.protocol.data.game.chunk.Column; -import org.spacehq.mc.protocol.util.NetUtil; -import org.spacehq.packetlib.io.NetInput; -import org.spacehq.packetlib.io.NetOutput; -import org.spacehq.packetlib.io.stream.StreamNetOutput; -import org.spacehq.packetlib.packet.Packet; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -public class ServerMultiChunkDataPacket implements Packet { - - private Column columns[]; - - @SuppressWarnings("unused") - private ServerMultiChunkDataPacket() { - } - - public ServerMultiChunkDataPacket(Column columns[]) { - boolean noSkylight = false; - boolean skylight = false; - for(Column column : columns) { - if(!column.hasSkylight()) { - noSkylight = true; - } else { - skylight = true; - } - } - - if(noSkylight && skylight) { - throw new IllegalArgumentException("Either all columns must have skylight values or none must have them."); - } - - this.columns = columns; - } - - public Column[] getColumns() { - return this.columns; - } - - @Override - public void read(NetInput in) throws IOException { - boolean skylight = in.readBoolean(); - int x[] = in.readInts(in.readVarInt()); - int z[] = in.readInts(in.readVarInt()); - int masks[] = in.readInts(in.readVarInt()); - byte data[] = in.readBytes(in.readVarInt()); - - Column columns[] = new Column[x.length]; - for(int i = 0; i < columns.length; i++) { - columns[i] = NetUtil.readColumn(data, x[i], z[i], true, skylight, masks[i]); - } - } - - @Override - public void write(NetOutput out) throws IOException { - Column columns[] = new Column[1]; - - boolean skylight = false; - for(Column column : columns) { - if(column.hasSkylight()) { - skylight = true; - break; - } - } - - out.writeBoolean(skylight); - - out.writeVarInt(columns.length); - for(Column column : columns) { - out.writeInt(column.getX()); - } - - out.writeVarInt(columns.length); - for(Column column : columns) { - out.writeInt(column.getZ()); - } - - out.writeVarInt(columns.length); - - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - NetOutput netOut = new StreamNetOutput(byteOut); - for(Column column : columns) { - out.writeInt(NetUtil.writeColumn(netOut, column, true, skylight)); - } - - out.writeVarInt(byteOut.size()); - out.writeBytes(byteOut.toByteArray(), byteOut.size()); - } - - @Override - public boolean isPriority() { - return false; - } - -} diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerUnloadChunkPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerUnloadChunkPacket.java new file mode 100644 index 00000000..7ca7a14b --- /dev/null +++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/world/ServerUnloadChunkPacket.java @@ -0,0 +1,46 @@ +package org.spacehq.mc.protocol.packet.ingame.server.world; + +import org.spacehq.packetlib.io.NetInput; +import org.spacehq.packetlib.io.NetOutput; +import org.spacehq.packetlib.packet.Packet; + +import java.io.IOException; + +public class ServerUnloadChunkPacket implements Packet { + private int x; + private int z; + + @SuppressWarnings("unused") + private ServerUnloadChunkPacket() { + } + + public ServerUnloadChunkPacket(int x, int z) { + this.x = x; + this.z = z; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } + + @Override + public void read(NetInput in) throws IOException { + this.x = in.readInt(); + this.z = in.readInt(); + } + + @Override + public void write(NetOutput out) throws IOException { + out.writeInt(this.x); + out.writeInt(this.z); + } + + @Override + public boolean isPriority() { + return false; + } +}