Parse block change value into id and data, minor cleanup.

This commit is contained in:
Steven Smith 2015-09-21 20:38:44 -07:00
parent b958e52ba5
commit 471d98ee4b
6 changed files with 25 additions and 40 deletions

View file

@ -3,41 +3,38 @@ package org.spacehq.mc.protocol.data.game.values.world.block;
import org.spacehq.mc.protocol.data.game.Position; import org.spacehq.mc.protocol.data.game.Position;
public class BlockChangeRecord { public class BlockChangeRecord {
private Position position; private Position position;
private int block; private int id;
private int data;
public BlockChangeRecord(Position position, int block) { public BlockChangeRecord(Position position, int id, int data) {
this.position = position; this.position = position;
this.block = block; this.id = id;
this.data = data;
} }
public Position getPosition() { public Position getPosition() {
return this.position; return this.position;
} }
public int getBlock() { public int getId() {
return this.block; return this.id;
}
public int getData() {
return this.data;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if(this == o) return true; return this == o || (o instanceof BlockChangeRecord && this.position.equals(((BlockChangeRecord) o).position) && this.id == ((BlockChangeRecord) o).id && this.data == ((BlockChangeRecord) o).data);
if(o == null || getClass() != o.getClass()) return false;
BlockChangeRecord record = (BlockChangeRecord) o;
if(block != record.block) return false;
if(!position.equals(record.position)) return false;
return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = position.hashCode(); int result = this.position.hashCode();
result = 31 * result + block; result = 31 * result + this.id;
result = 31 * result + this.data;
return result; return result;
} }
} }

View file

@ -1,7 +1,6 @@
package org.spacehq.mc.protocol.data.game.values.world.block; package org.spacehq.mc.protocol.data.game.values.world.block;
public class ExplodedBlockRecord { public class ExplodedBlockRecord {
private int x; private int x;
private int y; private int y;
private int z; private int z;
@ -26,24 +25,14 @@ public class ExplodedBlockRecord {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if(this == o) return true; return this == o || (o instanceof ExplodedBlockRecord && this.x == ((ExplodedBlockRecord) o).x && this.y == ((ExplodedBlockRecord) o).y && this.z == ((ExplodedBlockRecord) o).z);
if(o == null || getClass() != o.getClass()) return false;
ExplodedBlockRecord that = (ExplodedBlockRecord) o;
if(x != that.x) return false;
if(y != that.y) return false;
if(z != that.z) return false;
return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = x; int result = this.x;
result = 31 * result + y; result = 31 * result + this.y;
result = 31 * result + z; result = 31 * result + this.z;
return result; return result;
} }
} }

View file

@ -1,12 +1,10 @@
package org.spacehq.mc.protocol.data.game.values.world.block; package org.spacehq.mc.protocol.data.game.values.world.block;
public enum UpdatedTileType { public enum UpdatedTileType {
MOB_SPAWNER, MOB_SPAWNER,
COMMAND_BLOCK, COMMAND_BLOCK,
BEACON, BEACON,
SKULL, SKULL,
FLOWER_POT, FLOWER_POT,
BANNER; BANNER;
} }

View file

@ -26,13 +26,14 @@ public class ServerBlockChangePacket implements Packet {
@Override @Override
public void read(NetInput in) throws IOException { public void read(NetInput in) throws IOException {
this.record = new BlockChangeRecord(NetUtil.readPosition(in), in.readVarInt()); int block = in.readVarInt();
this.record = new BlockChangeRecord(NetUtil.readPosition(in), block >> 4, block & 0xF);
} }
@Override @Override
public void write(NetOutput out) throws IOException { public void write(NetOutput out) throws IOException {
NetUtil.writePosition(out, this.record.getPosition()); NetUtil.writePosition(out, this.record.getPosition());
out.writeVarInt(this.record.getBlock()); out.writeVarInt(this.record.getId() << 4 | (this.record.getData() & 0xF));
} }
@Override @Override

View file

@ -39,7 +39,7 @@ public class ServerMultiBlockChangePacket implements Packet {
int x = (chunkX << 4) + (pos >> 12 & 15); int x = (chunkX << 4) + (pos >> 12 & 15);
int y = pos & 255; int y = pos & 255;
int z = (chunkZ << 4) + (pos >> 8 & 15); int z = (chunkZ << 4) + (pos >> 8 & 15);
this.records[index] = new BlockChangeRecord(new Position(x, y, z), block); this.records[index] = new BlockChangeRecord(new Position(x, y, z), block >> 4, block & 0xF);
} }
} }
@ -52,7 +52,7 @@ public class ServerMultiBlockChangePacket implements Packet {
out.writeVarInt(this.records.length); out.writeVarInt(this.records.length);
for(BlockChangeRecord record : this.records) { for(BlockChangeRecord record : this.records) {
out.writeShort((record.getPosition().getX() - (chunkX << 4)) << 12 | (record.getPosition().getZ() - (chunkZ << 4)) << 8 | record.getPosition().getY()); out.writeShort((record.getPosition().getX() - (chunkX << 4)) << 12 | (record.getPosition().getZ() - (chunkZ << 4)) << 8 | record.getPosition().getY());
out.writeVarInt(record.getBlock()); out.writeVarInt(record.getId() << 4 | (record.getData() & 0xF));
} }
} }

View file

@ -21,7 +21,7 @@ public class ServerUpdateTileEntityPacket implements Packet {
private ServerUpdateTileEntityPacket() { private ServerUpdateTileEntityPacket() {
} }
public ServerUpdateTileEntityPacket(int breakerEntityId, Position position, UpdatedTileType type, CompoundTag nbt) { public ServerUpdateTileEntityPacket(Position position, UpdatedTileType type, CompoundTag nbt) {
this.position = position; this.position = position;
this.type = type; this.type = type;
this.nbt = nbt; this.nbt = nbt;