From 9a9f67b45f807206ec2ca837dee1c2377de37a67 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Fri, 13 Sep 2019 11:49:18 +0100 Subject: [PATCH] Get chunks working to some degree. --- .../org/geysermc/connector/entity/Entity.java | 13 +++++++------ .../connector/network/session/GeyserSession.java | 11 +++++------ .../java/world/JavaChunkDataTranslator.java | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index 30d61ad9b..b93cd79fc 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -29,6 +29,8 @@ import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket; import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.EntityDataDictionary; +import com.nukkitx.protocol.bedrock.data.EntityFlag; +import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket; import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket; @@ -41,12 +43,7 @@ import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.AttributeUtils; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; @Getter @Setter @@ -139,6 +136,9 @@ public class Entity { public EntityDataDictionary getMetadata() { + EntityFlags flags = new EntityFlags(); + flags.setFlag(EntityFlag.HAS_GRAVITY, true); + EntityDataDictionary dictionary = new EntityDataDictionary(); dictionary.put(EntityData.NAMETAG, ""); dictionary.put(EntityData.ENTITY_AGE, 0); @@ -147,6 +147,7 @@ public class Entity { dictionary.put(EntityData.AIR, (short) 0); dictionary.put(EntityData.BOUNDING_BOX_HEIGHT, entityType.getHeight()); dictionary.put(EntityData.BOUNDING_BOX_WIDTH, entityType.getWidth()); + dictionary.putFlags(flags); return dictionary; } diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 1a21edea7..3eed5adac 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.session; import com.flowpowered.math.vector.Vector2f; +import com.flowpowered.math.vector.Vector2i; import com.flowpowered.math.vector.Vector3f; import com.flowpowered.math.vector.Vector3i; import com.github.steveice10.mc.auth.exception.request.RequestException; @@ -47,7 +48,6 @@ import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.TextPacket; import lombok.Getter; import lombok.Setter; -import org.geysermc.api.Geyser; import org.geysermc.api.Player; import org.geysermc.api.RemoteServer; import org.geysermc.api.session.AuthData; @@ -56,11 +56,7 @@ import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.inventory.PlayerInventory; -import org.geysermc.connector.network.session.cache.DataCache; -import org.geysermc.connector.network.session.cache.EntityCache; -import org.geysermc.connector.network.session.cache.InventoryCache; -import org.geysermc.connector.network.session.cache.ScoreboardCache; -import org.geysermc.connector.network.session.cache.WindowCache; +import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.utils.Toolbox; @@ -87,6 +83,9 @@ public class GeyserSession implements PlayerSession, Player { private DataCache javaPacketCache; + @Setter + private Vector2i lastChunkPosition = null; + private boolean loggedIn; @Setter diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 15cfb26d4..9313102ca 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -1,8 +1,11 @@ package org.geysermc.connector.network.translators.java.world; +import com.flowpowered.math.vector.Vector2i; +import com.flowpowered.math.vector.Vector3f; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; +import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.geysermc.api.Geyser; @@ -18,6 +21,19 @@ public class JavaChunkDataTranslator extends PacketTranslator { + Vector2i chunkPos = session.getLastChunkPosition(); + Vector3f position = session.getPlayerEntity().getPosition(); + Vector2i newChunkPos = Vector2i.from(position.getFloorX() >> 4, position.getFloorZ() >> 4); + + if (chunkPos == null || !chunkPos.equals(newChunkPos)) { + NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); + chunkPublisherUpdatePacket.setPosition(position.toInt()); + chunkPublisherUpdatePacket.setRadius(8 << 4); + session.getUpstream().sendPacket(chunkPublisherUpdatePacket); + + session.setLastChunkPosition(newChunkPos); + } + try { ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); ByteBuf byteBuf = Unpooled.buffer(32);