mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Use chunk cache and fix ChunkPosition
getChunkBlock() in ChunkPosition returned incorrect values when negative numbers were inputted. ChunkPosition did not function correctly when used as a key for maps because it did not override equals() and hashCode()
This commit is contained in:
parent
46107df0f8
commit
3067c72746
5 changed files with 28 additions and 11 deletions
|
@ -40,6 +40,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
|
|||
public void translate(ServerPlayerActionAckPacket packet, GeyserSession session) {
|
||||
switch (packet.getAction()) {
|
||||
case FINISH_DIGGING:
|
||||
session.getChunkCache().updateBlock(packet.getPosition(), packet.getNewState());
|
||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||
updateBlockPacket.setDataLayer(0);
|
||||
updateBlockPacket.setBlockPosition(Vector3i.from(
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.geysermc.connector.network.translators.java.world;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
|
@ -13,8 +14,9 @@ import org.geysermc.connector.world.GlobalBlockPalette;
|
|||
public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> {
|
||||
@Override
|
||||
public void translate(ServerBlockChangePacket packet, GeyserSession session) {
|
||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||
BlockChangeRecord record = packet.getRecord();
|
||||
session.getChunkCache().updateBlock(record.getPosition(), record.getBlock());
|
||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||
updateBlockPacket.setDataLayer(0);
|
||||
updateBlockPacket.setBlockPosition(Vector3i.from(
|
||||
record.getPosition().getX(),
|
||||
|
|
|
@ -18,6 +18,7 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||
|
||||
@Override
|
||||
public void translate(ServerChunkDataPacket packet, GeyserSession session) {
|
||||
session.getChunkCache().addToCache(packet.getColumn());
|
||||
// Not sure if this is safe or not, however without this the client usually times out
|
||||
Geyser.getConnector().getGeneralThreadPool().execute(() -> {
|
||||
Vector2i chunkPos = session.getLastChunkPosition();
|
||||
|
|
|
@ -40,6 +40,7 @@ public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMulti
|
|||
@Override
|
||||
public void translate(ServerMultiBlockChangePacket packet, GeyserSession session) {
|
||||
for (BlockChangeRecord record : packet.getRecords()) {
|
||||
session.getChunkCache().updateBlock(record.getPosition(), record.getBlock());
|
||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||
updateBlockPacket.setDataLayer(0);
|
||||
updateBlockPacket.setBlockPosition(Vector3i.from(
|
||||
|
|
|
@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
|
@ -18,17 +20,27 @@ public class ChunkPosition {
|
|||
}
|
||||
|
||||
public Position getChunkBlock(int x, int y, int z) {
|
||||
int chunkX = x % 16;
|
||||
int chunkY = y % 16;
|
||||
int chunkZ = z % 16;
|
||||
|
||||
if (chunkX < 0)
|
||||
chunkX = -chunkX;
|
||||
if (chunkY < 0)
|
||||
chunkY = -chunkY;
|
||||
if (chunkZ < 0)
|
||||
chunkZ = -chunkZ;
|
||||
int chunkX = x & 15;
|
||||
int chunkY = y & 15;
|
||||
int chunkZ = z & 15;
|
||||
|
||||
return new Position(chunkX, chunkY, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (!(obj instanceof ChunkPosition))
|
||||
return false;
|
||||
ChunkPosition other = (ChunkPosition)obj;
|
||||
return x == other.x && z == other.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, z);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue