3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

(A lot) more work on entities

Dieser Commit ist enthalten in:
RednedEpic 2019-08-03 01:51:05 -05:00
Ursprung d496d4958e
Commit c114e4d541
26 geänderte Dateien mit 953 neuen und 111 gelöschten Zeilen

Datei anzeigen

@ -33,11 +33,14 @@ import com.nukkitx.protocol.bedrock.packet.AddEntityPacket;
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Getter
@Setter
@ -50,18 +53,19 @@ public class Entity {
protected Vector3f position;
protected Vector3f motion;
// 1 - pitch, 2 - yaw, 3 - roll (head yaw)
protected Vector3f rotation;
protected int scale = 1;
protected float yaw;
protected float pitch;
protected boolean shouldMove;
protected boolean movePending;
protected EntityType entityType;
protected boolean valid;
protected Map<Integer, Attribute> attributes = new HashMap<Integer, Attribute>();
protected Set<Long> passengers = new HashSet<Long>();
protected Map<Attribute, Integer> attributes = new HashMap<Attribute, Integer>();
public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
this.entityId = entityId;
@ -72,20 +76,24 @@ public class Entity {
this.rotation = rotation;
this.valid = false;
this.shouldMove = false;
this.movePending = false;
}
public void spawnEntity(GeyserSession session) {
AddEntityPacket addEntityPacket = new AddEntityPacket();
addEntityPacket.setIdentifier("minecraft:" + entityType.name().toLowerCase());
addEntityPacket.setRuntimeEntityId(geyserId);
addEntityPacket.setUniqueEntityId(entityId);
addEntityPacket.setUniqueEntityId(geyserId);
addEntityPacket.setPosition(position);
addEntityPacket.setMotion(motion);
addEntityPacket.setRotation(rotation);
addEntityPacket.setEntityType(entityType.getType());
addEntityPacket.getMetadata().putAll(getMetadata());
session.getUpstream().sendPacket(addEntityPacket);
valid = true;
session.getUpstream().sendPacket(addEntityPacket);
GeyserLogger.DEFAULT.debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")");
}
public void despawnEntity(GeyserSession session) {
@ -93,35 +101,38 @@ public class Entity {
return;
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(entityId);
removeEntityPacket.setUniqueEntityId(geyserId);
session.getUpstream().sendPacket(removeEntityPacket);
}
public void moveRelative(double relX, double relY, double relZ, float pitch, float yaw) {
if (relX == 0 && relY != 0 && relZ != 0 && yaw != 0 && pitch != 0)
moveRelative(relX, relY, relZ, new Vector3f(pitch, yaw, 0));
}
public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) {
if (relX == 0 && relY != 0 && relZ != 0 && position.getX() == 0 && position.getY() == 0)
return;
if (pitch != 0)
this.pitch = pitch;
if (yaw != 0)
this.yaw = yaw;
this.rotation = rotation;
this.position = new Vector3f(position.getX() + relX, position.getX() + relY, position.getX() + relZ);
this.shouldMove = true;
this.movePending = true;
}
public void moveAbsolute(Vector3f position, float pitch, float yaw) {
if (position.getX() == 0 && position.getX() != 0 && position.getX() != 0 && yaw != 0 && pitch != 0)
moveAbsolute(position, new Vector3f(pitch, yaw, 0));
}
public void moveAbsolute(Vector3f position, Vector3f rotation) {
if (position.getX() == 0 && position.getX() != 0 && position.getX() != 0 && rotation.getX() == 0 && rotation.getY() == 0)
return;
this.position = position;
this.pitch = pitch;
this.yaw = yaw;
this.shouldMove = true;
this.rotation = rotation;
this.movePending = true;
}
protected EntityDataDictionary getMetadata() {
public EntityDataDictionary getMetadata() {
EntityDataDictionary dictionary = new EntityDataDictionary();
dictionary.put(EntityData.NAMETAG, "");
dictionary.put(EntityData.ENTITY_AGE, 0);

Datei anzeigen

@ -0,0 +1,52 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.entity;
import com.flowpowered.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
public class ExpOrbEntity extends Entity {
private int amount;
public ExpOrbEntity(int amount, long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
this.amount = amount;
}
@Override
public void spawnEntity(GeyserSession session) {
SpawnExperienceOrbPacket spawnExpOrbPacket = new SpawnExperienceOrbPacket();
spawnExpOrbPacket.setPosition(position);
spawnExpOrbPacket.setAmount(amount);
valid = true;
session.getUpstream().sendPacket(spawnExpOrbPacket);
}
}

Datei anzeigen

@ -37,12 +37,14 @@ import lombok.Setter;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import java.util.Random;
import java.util.UUID;
@Getter
@Setter
public class PlayerEntity extends Entity {
// This is the session linked to the player entity, can be null
private GeyserSession session;
private UUID uuid;
private ItemData hand;
@ -51,10 +53,10 @@ public class PlayerEntity extends Entity {
private ItemData leggings;
private ItemData boots;
public PlayerEntity(GeyserSession session, long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
public PlayerEntity(UUID uuid, long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
this.session = session;
this.uuid = uuid;
}
// TODO: Break this into an EquippableEntity class
@ -76,9 +78,9 @@ public class PlayerEntity extends Entity {
public void spawnEntity(GeyserSession session) {
AddPlayerPacket addPlayerPacket = new AddPlayerPacket();
addPlayerPacket.setUniqueEntityId(geyserId);
addPlayerPacket.setUniqueEntityId(entityId);
addPlayerPacket.setUuid(this.session.getAuthenticationData().getUUID());
addPlayerPacket.setUsername(this.session.getAuthenticationData().getName());
addPlayerPacket.setUniqueEntityId(geyserId);
addPlayerPacket.setUuid(uuid);
addPlayerPacket.setUsername("Player" + new Random().nextInt(1000) + 1); // TODO: Cache player list values and set it here
addPlayerPacket.setPlatformChatId("");
addPlayerPacket.setPosition(position);
addPlayerPacket.setMotion(motion);
@ -91,6 +93,9 @@ public class PlayerEntity extends Entity {
addPlayerPacket.setPlayerPermission(0);
addPlayerPacket.setCustomFlags(0);
addPlayerPacket.setDeviceId("WIN10"); // TODO: Find this value
addPlayerPacket.getMetadata().putAll(getMetadata());
valid = true;
session.getUpstream().sendPacket(addPlayerPacket);
}
}

Datei anzeigen

@ -35,6 +35,7 @@ import com.github.steveice10.packetlib.event.session.ConnectedEvent;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import com.nukkitx.network.util.DisconnectReason;
import com.nukkitx.protocol.PlayerSession;
@ -45,6 +46,7 @@ import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.packet.TextPacket;
import lombok.Getter;
import lombok.Setter;
import org.geysermc.api.Player;
import org.geysermc.api.RemoteServer;
import org.geysermc.api.session.AuthData;
@ -52,6 +54,7 @@ import org.geysermc.api.window.FormWindow;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
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;
@ -59,53 +62,48 @@ import org.geysermc.connector.network.session.cache.WindowCache;
import org.geysermc.connector.network.translators.Registry;
import org.geysermc.connector.utils.Toolbox;
import java.util.UUID;
@Getter
public class GeyserSession implements PlayerSession, Player {
private GeyserConnector connector;
@Getter
private RemoteServer remoteServer;
@Getter
private BedrockServerSession upstream;
@Getter
private Client downstream;
@Getter
private AuthData authenticationData;
@Getter
private PlayerEntity playerEntity;
@Getter
private EntityCache entityCache;
@Getter
private InventoryCache inventoryCache;
@Getter
private WindowCache windowCache;
@Getter
private ScoreboardCache scoreboardCache;
@Getter
private DataCache<Packet> javaPacketCache;
private boolean loggedIn;
@Setter
private boolean spawned;
private boolean closed;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
this.connector = connector;
this.upstream = bedrockServerSession;
this.playerEntity = new PlayerEntity(this, 1, 1, EntityType.PLAYER, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
this.playerEntity = new PlayerEntity(UUID.randomUUID(), 1, 1, EntityType.PLAYER, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
this.entityCache = new EntityCache(this);
this.inventoryCache = new InventoryCache(this);
this.windowCache = new WindowCache(this);
this.scoreboardCache = new ScoreboardCache(this);
this.javaPacketCache = new DataCache<Packet>();
this.spawned = false;
this.loggedIn = false;
}
@ -145,6 +143,7 @@ public class GeyserSession implements PlayerSession, Player {
public void connected(ConnectedEvent event) {
loggedIn = true;
connector.getLogger().info(authenticationData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress());
playerEntity.setUuid(protocol.getProfile().getId());
}
@Override
@ -237,13 +236,13 @@ public class GeyserSession implements PlayerSession, Player {
private void startGame() {
StartGamePacket startGamePacket = new StartGamePacket();
startGamePacket.setUniqueEntityId(1); // TODO: Cache this value
startGamePacket.setRuntimeEntityId(1); // TODO: Cache this value
startGamePacket.setUniqueEntityId(1);
startGamePacket.setRuntimeEntityId(1);
startGamePacket.setPlayerGamemode(0);
startGamePacket.setPlayerPosition(new Vector3f(0, 0, 0));
startGamePacket.setRotation(new Vector2f(1, 1));
startGamePacket.setSeed(1111);
startGamePacket.setSeed(0);
startGamePacket.setDimensionId(0);
startGamePacket.setGeneratorId(0);
startGamePacket.setLevelGamemode(0);
@ -274,7 +273,7 @@ public class GeyserSession implements PlayerSession, Player {
startGamePacket.setFromWorldTemplate(false);
startGamePacket.setWorldTemplateOptionLocked(false);
startGamePacket.setLevelId("oerjhii");
startGamePacket.setLevelId("world");
startGamePacket.setWorldName("world");
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
startGamePacket.setCurrentTick(0);

Datei anzeigen

@ -0,0 +1,37 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.session.cache;
import lombok.Getter;
import java.util.HashMap;
import java.util.Map;
public class DataCache<T> {
@Getter
private Map<String, T> cachedValues = new HashMap<String, T>();
}

Datei anzeigen

@ -25,22 +25,18 @@
package org.geysermc.connector.network.session.cache;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
import lombok.Getter;
import org.geysermc.api.Geyser;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.EntityUtils;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
// Each session has its own EntityCache in the occasion that an entity packet is sent specifically
// for that player (e.g. seeing vanished players from /vanish)
/**
* Each session has its own EntityCache in the occasion that an entity packet is sent specifically
* for that player (e.g. seeing vanished players from /vanish)
*/
public class EntityCache {
private GeyserSession session;
@ -48,25 +44,35 @@ public class EntityCache {
@Getter
private Map<Long, Entity> entities = new HashMap<Long, Entity>();
private Map<Long, Long> entityIdTranslations = new HashMap<Long, Long>();
@Getter
private AtomicLong nextEntityId = new AtomicLong(2L);
public EntityCache(GeyserSession session) {
this.session = session;
}
public Entity spawnEntity(ServerSpawnMobPacket packet) {
EntityType type = EntityUtils.toBedrockEntity(packet.getType());
if (type == null) {
GeyserLogger.DEFAULT.warning("Mob " + packet.getType() + " is not supported yet!");
return null;
public void spawnEntity(Entity entity) {
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
entities.put(entity.getGeyserId(), entity);
entity.spawnEntity(session);
}
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), packet.getHeadYaw());
public void removeEntity(Entity entity) {
if (entity == null)
return;
Entity entity = new Entity(packet.getEntityId(), nextEntityId.incrementAndGet(), type, position, motion, rotation);
entity.moveAbsolute(position, packet.getPitch(), packet.getYaw());
return entities.put(entity.getGeyserId(), entity);
entityIdTranslations.remove(entity.getGeyserId());
entity.despawnEntity(session);
}
public Entity getEntityByGeyserId(long geyserId) {
return entities.get(geyserId);
}
public Entity getEntityByJavaId(long javaId) {
return entities.get(entityIdTranslations.get(javaId));
}
}

Datei anzeigen

@ -30,11 +30,21 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
@ -57,11 +67,21 @@ import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.java.JavaChatTranslator;
import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityDestroyTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityHeadLookTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityMetadataTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionRotationTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityPositionTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityPropertiesTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityRotationTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityTeleportTranslator;
import org.geysermc.connector.network.translators.java.entity.JavaEntityVelocityTranslator;
import org.geysermc.connector.network.translators.java.entity.player.JavaPlayerPositionRotationTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnExpOrbTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnGlobalEntityTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnMobTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnObjectTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPaintingTranslator;
import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPlayerTranslator;
import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator;
import org.geysermc.connector.network.translators.java.window.JavaOpenWindowTranslator;
import org.geysermc.connector.network.translators.java.window.JavaSetSlotTranslator;
@ -104,13 +124,27 @@ public class TranslatorsInit {
Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator());
Registry.registerJava(ServerTitlePacket.class, new JavaTitleTranslator());
Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator());
Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator());
Registry.registerJava(ServerEntityPositionRotationPacket.class, new JavaEntityPositionRotationTranslator());
Registry.registerJava(ServerEntityTeleportPacket.class, new JavaEntityTeleportTranslator());
Registry.registerJava(ServerEntityVelocityPacket.class, new JavaEntityVelocityTranslator());
Registry.registerJava(ServerEntityPropertiesPacket.class, new JavaEntityPropertiesTranslator());
Registry.registerJava(ServerEntityRotationPacket.class, new JavaEntityRotationTranslator());
Registry.registerJava(ServerEntityHeadLookPacket.class, new JavaEntityHeadLookTranslator());
Registry.registerJava(ServerEntityMetadataPacket.class, new JavaEntityMetadataTranslator());
Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator());
Registry.registerJava(ServerSpawnGlobalEntityPacket.class, new JavaSpawnGlobalEntityTranslator());
Registry.registerJava(ServerSpawnMobPacket.class, new JavaSpawnMobTranslator());
Registry.registerJava(ServerSpawnObjectPacket.class, new JavaSpawnObjectTranslator());
Registry.registerJava(ServerSpawnPaintingPacket.class, new JavaSpawnPaintingTranslator());
Registry.registerJava(ServerSpawnPlayerPacket.class, new JavaSpawnPlayerTranslator());
Registry.registerJava(ServerPlayerPositionRotationPacket.class, new JavaPlayerPositionRotationTranslator());
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator());
Registry.registerJava(ServerSpawnExpOrbPacket.class, new JavaSpawnExpOrbTranslator());
Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator());
Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator());
Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator());

Datei anzeigen

@ -38,7 +38,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
@Override
public void translate(ServerJoinGamePacket packet, GeyserSession session) {
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
bedrockPacket.setUniqueEntityId(packet.getEntityId());
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
session.getUpstream().sendPacketImmediately(bedrockPacket);
Vector3f pos = new Vector3f(0, 0, 0);
@ -52,10 +52,11 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
data.setSubChunksLength(0);
data.setData(TranslatorsInit.EMPTY_LEVEL_CHUNK_DATA);
session.getUpstream().sendPacketImmediately(data);
}
}
session.getJavaPacketCache().getCachedValues().put("java_join_packet", packet);
}
}

Datei anzeigen

@ -27,6 +27,7 @@ package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityDestroyPacket;
import com.nukkitx.protocol.bedrock.packet.RemoveEntityPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -35,10 +36,8 @@ public class JavaEntityDestroyTranslator extends PacketTranslator<ServerEntityDe
@Override
public void translate(ServerEntityDestroyPacket packet, GeyserSession session) {
for (int entityId : packet.getEntityIds()) {
RemoveEntityPacket removeEntityPacket = new RemoveEntityPacket();
removeEntityPacket.setUniqueEntityId(entityId);
session.getUpstream().sendPacket(removeEntityPacket);
Entity entity = session.getEntityCache().getEntityByJavaId(entityId);
session.getEntityCache().removeEntity(entity);
}
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaEntityHeadLookTranslator extends PacketTranslator<ServerEntityHeadLookPacket> {
@Override
public void translate(ServerEntityHeadLookPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.setRotation(new Vector3f(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw()));
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityAbsolutePacket.setRotation(entity.getRotation());
moveEntityAbsolutePacket.setPosition(entity.getPosition());
moveEntityAbsolutePacket.setOnGround(true);
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
}
}

Datei anzeigen

@ -0,0 +1,56 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaEntityMetadataTranslator extends PacketTranslator<ServerEntityMetadataPacket> {
@Override
public void translate(ServerEntityMetadataPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
if (entity.isValid()) {
// TODO: Make this actually useful lol
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
entityDataPacket.getMetadata().putAll(entity.getMetadata());
session.getUpstream().sendPacket(entityDataPacket);
} else {
entity.spawnEntity(session);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@
package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -35,13 +35,25 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator<Serve
@Override
public void translate(ServerEntityPositionRotationPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getPitch(), packet.getYaw());
if (entity.isMovePending()) {
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
moveEntityPacket.setRuntimeEntityId(packet.getEntityId());
moveEntityPacket.setPosition(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()));
moveEntityPacket.setRotation(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()));
moveEntityPacket.setOnGround(true);
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityPacket.setPosition(entity.getPosition());
moveEntityPacket.setRotation(entity.getRotation());
moveEntityPacket.setOnGround(packet.isOnGround());
moveEntityPacket.setTeleported(false);
entity.setMovePending(false);
session.getUpstream().sendPacket(moveEntityPacket);
}
}
}

Datei anzeigen

@ -25,9 +25,9 @@
package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -35,13 +35,25 @@ public class JavaEntityPositionTranslator extends PacketTranslator<ServerEntityP
@Override
public void translate(ServerEntityPositionPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getPitch(), packet.getYaw());
if (entity.isMovePending()) {
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
moveEntityPacket.setRuntimeEntityId(packet.getEntityId());
moveEntityPacket.setPosition(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()));
moveEntityPacket.setRotation(new Vector3f(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ()));
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityPacket.setPosition(entity.getPosition());
moveEntityPacket.setRotation(entity.getRotation());
moveEntityPacket.setOnGround(packet.isOnGround());
moveEntityPacket.setTeleported(false);
entity.setMovePending(false);
session.getUpstream().sendPacket(moveEntityPacket);
}
}
}

Datei anzeigen

@ -0,0 +1,45 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaEntityPropertiesTranslator extends PacketTranslator<ServerEntityPropertiesPacket> {
@Override
public void translate(ServerEntityPropertiesPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
}
}

Datei anzeigen

@ -0,0 +1,60 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaEntityRotationTranslator extends PacketTranslator<ServerEntityRotationPacket> {
@Override
public void translate(ServerEntityRotationPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getPitch(), packet.getYaw());
Vector3f rotation = new Vector3f(entity.getRotation().getX() / (360d / 256d), entity.getRotation().getY() / (360d / 256d),
entity.getRotation().getZ() / (360d / 256d));
if (entity.isMovePending()) {
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityAbsolutePacket.setPosition(entity.getPosition());
moveEntityAbsolutePacket.setRotation(rotation);
entity.setMovePending(false);
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
}
}
}

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -35,13 +36,25 @@ public class JavaEntityTeleportTranslator extends PacketTranslator<ServerEntityT
@Override
public void translate(ServerEntityTeleportPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.moveAbsolute(new Vector3f(packet.getX(), packet.getY(), packet.getZ()), packet.getPitch(), packet.getYaw());
if (entity.isMovePending()) {
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
moveEntityPacket.setRuntimeEntityId(packet.getEntityId());
moveEntityPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
moveEntityPacket.setRotation(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityPacket.setPosition(entity.getPosition());
moveEntityPacket.setRotation(entity.getRotation());
moveEntityPacket.setOnGround(packet.isOnGround());
moveEntityPacket.setTeleported(true);
entity.setMovePending(false);
session.getUpstream().sendPacket(moveEntityPacket);
}
}
}

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java.entity;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityVelocityPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
@ -35,9 +36,18 @@ public class JavaEntityVelocityTranslator extends PacketTranslator<ServerEntityV
@Override
public void translate(ServerEntityVelocityPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
entity.setMotion(new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()));
SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket();
entityMotionPacket.setRuntimeEntityId(packet.getEntityId());
entityMotionPacket.setMotion(new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ()));
entityMotionPacket.setRuntimeEntityId(entity.getGeyserId());
entityMotionPacket.setMotion(entity.getMotion());
session.getUpstream().sendPacket(entityMotionPacket);
}

Datei anzeigen

@ -0,0 +1,128 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.player;
import com.flowpowered.math.vector.Vector2f;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector3i;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
import com.nukkitx.protocol.bedrock.data.GameRule;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.utils.Toolbox;
public class JavaPlayerPositionRotationTranslator extends PacketTranslator<ServerPlayerPositionRotationPacket> {
@Override
public void translate(ServerPlayerPositionRotationPacket packet, GeyserSession session) {
Entity entity = session.getPlayerEntity();
if (entity == null)
return;
if (!session.isLoggedIn())
return;
if (session.isSpawned())
return;
ServerJoinGamePacket javaPacket = (ServerJoinGamePacket) session.getJavaPacketCache().getCachedValues().remove("java_join_packet");
StartGamePacket startGamePacket = new StartGamePacket();
startGamePacket.setUniqueEntityId(entity.getEntityId());
startGamePacket.setRuntimeEntityId(entity.getEntityId());
startGamePacket.setPlayerGamemode(0);
startGamePacket.setPlayerPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
startGamePacket.setRotation(new Vector2f(entity.getRotation().getX(), entity.getRotation().getY()));
startGamePacket.setSeed(0);
startGamePacket.setDimensionId(entity.getDimension());
startGamePacket.setGeneratorId(0);
startGamePacket.setLevelGamemode(javaPacket.getGameMode().ordinal());
startGamePacket.setDifficulty(1);
startGamePacket.setDefaultSpawn(new Vector3i(packet.getX(), packet.getY(), packet.getZ()));
startGamePacket.setAcheivementsDisabled(true);
startGamePacket.setTime(0);
startGamePacket.setEduLevel(false);
startGamePacket.setEduFeaturesEnabled(false);
startGamePacket.setRainLevel(0);
startGamePacket.setLightningLevel(0);
startGamePacket.setMultiplayerGame(true);
startGamePacket.setBroadcastingToLan(true);
startGamePacket.getGamerules().add(new GameRule<>("showcoordinates", true));
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
startGamePacket.setCommandsEnabled(true);
startGamePacket.setTexturePacksRequired(false);
startGamePacket.setBonusChestEnabled(false);
startGamePacket.setStartingWithMap(false);
startGamePacket.setTrustingPlayers(true);
startGamePacket.setDefaultPlayerPermission(1);
startGamePacket.setServerChunkTickRange(4);
startGamePacket.setBehaviorPackLocked(false);
startGamePacket.setResourcePackLocked(false);
startGamePacket.setFromLockedWorldTemplate(false);
startGamePacket.setUsingMsaGamertagsOnly(false);
startGamePacket.setFromWorldTemplate(false);
startGamePacket.setWorldTemplateOptionLocked(false);
startGamePacket.setLevelId("world");
startGamePacket.setWorldName("world");
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
startGamePacket.setCurrentTick(0);
startGamePacket.setEnchantmentSeed(0);
startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
startGamePacket.setItemEntries(Toolbox.ITEMS);
session.getUpstream().sendPacket(startGamePacket);
entity.moveAbsolute(new Vector3f(packet.getX(), packet.getY(), packet.getZ()), packet.getPitch(), packet.getYaw());
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
entityDataPacket.getMetadata().putAll(entity.getMetadata());
session.getUpstream().sendPacket(entityDataPacket);
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
movePlayerPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
movePlayerPacket.setRotation(new Vector3f(packet.getPitch(), packet.getYaw(), 0));
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
movePlayerPacket.setOnGround(true);
entity.setMovePending(false);
session.getUpstream().sendPacket(movePlayerPacket);
session.setSpawned(true);
System.out.println("resent! " + packet.getX() + " " + packet.getY() + " " + packet.getZ());
}
}

Datei anzeigen

@ -1,19 +1,51 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnExpOrbPacket;
import com.nukkitx.protocol.bedrock.packet.SpawnExperienceOrbPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ExpOrbEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.utils.EntityUtils;
public class JavaSpawnExpOrbTranslator extends PacketTranslator<ServerSpawnExpOrbPacket> {
@Override
public void translate(ServerSpawnExpOrbPacket packet, GeyserSession session) {
SpawnExperienceOrbPacket spawnExperienceOrbPacket = new SpawnExperienceOrbPacket();
spawnExperienceOrbPacket.setPosition(new Vector3f(packet.getX(), packet.getY(), packet.getZ()));
spawnExperienceOrbPacket.setAmount(packet.getExp());
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Entity entity = new ExpOrbEntity(packet.getExp(), packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
EntityType.EXPERIENCE_ORB, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
session.getUpstream().sendPacket(spawnExperienceOrbPacket);
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -0,0 +1,50 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnGlobalEntityPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaSpawnGlobalEntityTranslator extends PacketTranslator<ServerSpawnGlobalEntityPacket> {
@Override
public void translate(ServerSpawnGlobalEntityPacket packet, GeyserSession session) {
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
// Currently GlobalEntityType only has a lightning bolt
Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
EntityType.LIGHTNING_BOLT, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -0,0 +1,59 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnMobPacket;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.utils.EntityUtils;
public class JavaSpawnMobTranslator extends PacketTranslator<ServerSpawnMobPacket> {
@Override
public void translate(ServerSpawnMobPacket packet, GeyserSession session) {
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), packet.getHeadYaw());
EntityType type = EntityUtils.toBedrockEntity(packet.getType());
if (type == null) {
GeyserLogger.DEFAULT.warning("Entity type " + packet.getType() + " was null.");
return;
}
Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation);
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnObjectPacket;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.utils.EntityUtils;
public class JavaSpawnObjectTranslator extends PacketTranslator<ServerSpawnObjectPacket> {
@Override
public void translate(ServerSpawnObjectPacket packet, GeyserSession session) {
if (packet.getType() == ObjectType.ITEM_FRAME)
return;
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Vector3f motion = new Vector3f(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), 0);
EntityType type = EntityUtils.toBedrockEntity(packet.getType());
if (type == null) {
GeyserLogger.DEFAULT.warning("Entity type " + packet.getType() + " was null.");
return;
}
Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation);
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -0,0 +1,49 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPaintingPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPaintingPacket> {
@Override
public void translate(ServerSpawnPaintingPacket packet, GeyserSession session) {
Vector3f position = new Vector3f(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
Entity entity = new Entity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
EntityType.PAINTING, position, new Vector3f(0, 0, 0), new Vector3f(0, 0, 0));
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -0,0 +1,50 @@
/*
* Copyright (c) 2019 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java.entity.spawn;
import com.flowpowered.math.vector.Vector3f;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.spawn.ServerSpawnPlayerPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlayerPacket> {
@Override
public void translate(ServerSpawnPlayerPacket packet, GeyserSession session) {
Vector3f position = new Vector3f(packet.getX(), packet.getY(), packet.getZ());
Vector3f rotation = new Vector3f(packet.getPitch(), packet.getYaw(), 0);
Entity entity = new PlayerEntity(packet.getUUID(), packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
EntityType.EXPERIENCE_ORB, position, new Vector3f(0, 0, 0), rotation);
if (entity == null)
return;
session.getEntityCache().spawnEntity(entity);
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.entity.type.MobType;
import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType;
import org.geysermc.connector.entity.type.EntityType;
public class EntityUtils {
@ -20,4 +21,12 @@ public class EntityUtils {
return null;
}
}
public static EntityType toBedrockEntity(ObjectType type) {
try {
return EntityType.valueOf(type.name());
} catch (IllegalArgumentException ex) {
return null;
}
}
}

Datei anzeigen

@ -1,23 +1,17 @@
package org.geysermc.connector.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import com.nukkitx.protocol.bedrock.v361.BedrockUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.apache.logging.log4j.core.util.Patterns;
import org.geysermc.connector.network.translators.item.BedrockItem;
import org.geysermc.connector.network.translators.item.DyeColor;
import org.geysermc.connector.network.translators.item.JavaItem;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Pattern;
public class Toolbox {