mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-04 12:51:09 -05:00
Parse block change value into id and data, minor cleanup.
This commit is contained in:
parent
b958e52ba5
commit
471d98ee4b
6 changed files with 25 additions and 40 deletions
|
@ -3,41 +3,38 @@ package org.spacehq.mc.protocol.data.game.values.world.block;
|
|||
import org.spacehq.mc.protocol.data.game.Position;
|
||||
|
||||
public class BlockChangeRecord {
|
||||
|
||||
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.block = block;
|
||||
this.id = id;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Position getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public int getBlock() {
|
||||
return this.block;
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
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;
|
||||
return this == o || (o instanceof BlockChangeRecord && this.position.equals(((BlockChangeRecord) o).position) && this.id == ((BlockChangeRecord) o).id && this.data == ((BlockChangeRecord) o).data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = position.hashCode();
|
||||
result = 31 * result + block;
|
||||
int result = this.position.hashCode();
|
||||
result = 31 * result + this.id;
|
||||
result = 31 * result + this.data;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.spacehq.mc.protocol.data.game.values.world.block;
|
||||
|
||||
public class ExplodedBlockRecord {
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
@ -26,24 +25,14 @@ public class ExplodedBlockRecord {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
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;
|
||||
return this == o || (o instanceof ExplodedBlockRecord && this.x == ((ExplodedBlockRecord) o).x && this.y == ((ExplodedBlockRecord) o).y && this.z == ((ExplodedBlockRecord) o).z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = x;
|
||||
result = 31 * result + y;
|
||||
result = 31 * result + z;
|
||||
int result = this.x;
|
||||
result = 31 * result + this.y;
|
||||
result = 31 * result + this.z;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
package org.spacehq.mc.protocol.data.game.values.world.block;
|
||||
|
||||
public enum UpdatedTileType {
|
||||
|
||||
MOB_SPAWNER,
|
||||
COMMAND_BLOCK,
|
||||
BEACON,
|
||||
SKULL,
|
||||
FLOWER_POT,
|
||||
BANNER;
|
||||
|
||||
}
|
||||
|
|
|
@ -26,13 +26,14 @@ public class ServerBlockChangePacket implements Packet {
|
|||
|
||||
@Override
|
||||
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
|
||||
public void write(NetOutput out) throws IOException {
|
||||
NetUtil.writePosition(out, this.record.getPosition());
|
||||
out.writeVarInt(this.record.getBlock());
|
||||
out.writeVarInt(this.record.getId() << 4 | (this.record.getData() & 0xF));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ public class ServerMultiBlockChangePacket implements Packet {
|
|||
int x = (chunkX << 4) + (pos >> 12 & 15);
|
||||
int y = pos & 255;
|
||||
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);
|
||||
for(BlockChangeRecord record : this.records) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ServerUpdateTileEntityPacket implements Packet {
|
|||
private ServerUpdateTileEntityPacket() {
|
||||
}
|
||||
|
||||
public ServerUpdateTileEntityPacket(int breakerEntityId, Position position, UpdatedTileType type, CompoundTag nbt) {
|
||||
public ServerUpdateTileEntityPacket(Position position, UpdatedTileType type, CompoundTag nbt) {
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
this.nbt = nbt;
|
||||
|
|
Loading…
Reference in a new issue