Get the basics working

This commit is contained in:
Luke 2020-09-26 02:37:13 +01:00
parent d9b05f5b72
commit 4bbb057f62
No known key found for this signature in database
GPG key ID: 27CA82F5031EB5B0
11 changed files with 143 additions and 4 deletions

View file

@ -56,10 +56,7 @@ import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter @Getter
@Setter @Setter
@ -67,6 +64,8 @@ public class Entity {
protected long entityId; protected long entityId;
protected long geyserId; protected long geyserId;
protected UUID javaUuid;
protected String dimension; protected String dimension;
protected Vector3f position; protected Vector3f position;

View file

@ -47,10 +47,13 @@ import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.data.*; import com.nukkitx.protocol.bedrock.data.*;
import com.nukkitx.protocol.bedrock.data.command.CommandPermission; import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps; import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import lombok.Getter; import lombok.Getter;
@ -62,6 +65,7 @@ import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.common.AuthType; import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.remote.RemoteServer; import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.auth.AuthData; import org.geysermc.connector.network.session.auth.AuthData;
@ -261,6 +265,11 @@ public class GeyserSession implements CommandSender {
@Setter @Setter
private String lastSignMessage; private String lastSignMessage;
private Entity spectatingEntity = null;
private Vector3f originalPosition = null;
private Vector3f originalRotation = null;
private boolean originalOnGround = false;
private MinecraftProtocol protocol; private MinecraftProtocol protocol;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) { public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
@ -751,4 +760,53 @@ public class GeyserSession implements CommandSender {
adventureSettingsPacket.getSettings().addAll(flags); adventureSettingsPacket.getSettings().addAll(flags);
sendUpstreamPacket(adventureSettingsPacket); sendUpstreamPacket(adventureSettingsPacket);
} }
public void stopSpectatingEntity() {
playerEntity.updatePositionAndRotation(this, originalPosition.getX(), originalPosition.getY(), originalPosition.getZ(),
originalRotation.getZ(), originalRotation.getY(), originalOnGround);
SetEntityLinkPacket linkPacket = new SetEntityLinkPacket();
linkPacket.setEntityLink(new EntityLinkData(spectatingEntity.getGeyserId(), playerEntity.getGeyserId(), EntityLinkData.Type.REMOVE, false));
this.sendUpstreamPacket(linkPacket);
spectatingEntity.getPassengers().remove(playerEntity.getEntityId());
spectatingEntity = null;
this.sendMessage("Stopping spectating entity");
}
public void setSpectatingEntity(Entity entity) {
this.sendMessage("Starting spectating entity");
originalPosition = playerEntity.getPosition();
originalRotation = playerEntity.getRotation();
originalOnGround = playerEntity.isOnGround();
SetEntityLinkPacket linkPacket = new SetEntityLinkPacket();
linkPacket.setEntityLink(new EntityLinkData(entity.getGeyserId(), playerEntity.getGeyserId(),
EntityLinkData.Type.RIDER, false));
this.sendUpstreamPacket(linkPacket);
entity.getPassengers().add(playerEntity.getEntityId());
spectatingEntity = entity;
}
public void sendSpectateLocation() {
Vector3f pos = spectatingEntity.getPosition();
Vector3f rot = spectatingEntity.getRotation();
playerEntity.updatePositionAndRotation(this, pos.getX(), pos.getY(), pos.getZ(), rot.getZ(), rot.getY(), spectatingEntity.isOnGround());
SetTitlePacket setTitlePacket = new SetTitlePacket();
setTitlePacket.setFadeOutTime(0);
setTitlePacket.setFadeInTime(0);
setTitlePacket.setStayTime(30);
setTitlePacket.setText("Sending position: " + pos.getX() + " " + pos.getY() + " " + pos.getZ());
setTitlePacket.setType(SetTitlePacket.Type.ACTIONBAR);
this.sendUpstreamPacket(setTitlePacket);
}
} }

View file

@ -36,6 +36,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSpectatePacket;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
@ -45,6 +46,7 @@ import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket; import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.CommandBlockMinecartEntity; import org.geysermc.connector.entity.CommandBlockMinecartEntity;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ItemFrameEntity; import org.geysermc.connector.entity.ItemFrameEntity;
@ -242,6 +244,15 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
//https://wiki.vg/Protocol#Interact_Entity //https://wiki.vg/Protocol#Interact_Entity
switch (packet.getActionType()) { switch (packet.getActionType()) {
case 0: //Interact case 0: //Interact
if (session.getGameMode() == GameMode.SPECTATOR) {
if (entity.getJavaUuid() == null) {
GeyserConnector.getInstance().getLogger().warning("DEBUG: Tried to spectate entity with no Java UUID");
return;
}
session.sendDownstreamPacket(new ClientSpectatePacket(entity.getJavaUuid()));
return;
}
if (entity instanceof CommandBlockMinecartEntity) { if (entity instanceof CommandBlockMinecartEntity) {
// The UI is handled client-side on Java Edition // The UI is handled client-side on Java Edition
// Ensure OP permission level and gamemode is appropriate // Ensure OP permission level and gamemode is appropriate

View file

@ -25,6 +25,7 @@
package org.geysermc.connector.network.translators.bedrock.entity.player; package org.geysermc.connector.network.translators.bedrock.entity.player;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap; import com.nukkitx.protocol.bedrock.data.entity.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
@ -76,6 +77,10 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
ClientPlayerStatePacket sneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING); ClientPlayerStatePacket sneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
session.sendDownstreamPacket(sneakPacket); session.sendDownstreamPacket(sneakPacket);
session.setRidingVehicleEntity(null); session.setRidingVehicleEntity(null);
if (session.getGameMode() == GameMode.SPECTATOR && session.getSpectatingEntity() != null) {
//session.stopSpectatingEntity();
}
break; break;
case MOUSEOVER: case MOUSEOVER:
// Handle the buttons for mobile - "Mount", etc; and the suggestions for console - "ZL: Mount", etc // Handle the buttons for mobile - "Mount", etc; and the suggestions for console - "ZL: Mount", etc

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2019-2020 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;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerSwitchCameraPacket;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
@Translator(packet = ServerSwitchCameraPacket.class)
public class JavaSwitchCameraTranslator extends PacketTranslator<ServerSwitchCameraPacket> {
@Override
public void translate(ServerSwitchCameraPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getCameraEntityId());
if (session.getPlayerEntity().getEntityId() == packet.getCameraEntityId()) {
entity = session.getPlayerEntity();
}
if (entity == null)
return;
if (session.getSpectatingEntity() != null && session.getPlayerEntity().getGeyserId() == entity.getGeyserId()) {
session.stopSpectatingEntity();
return;
}
session.setSpectatingEntity(entity);
}
}

View file

@ -43,5 +43,9 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator<Serve
if (entity == null) return; if (entity == null) return;
entity.updatePositionAndRotation(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch(), packet.isOnGround()); entity.updatePositionAndRotation(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch(), packet.isOnGround());
if (session.getSpectatingEntity() != null && session.getSpectatingEntity().getGeyserId() == entity.getGeyserId()) {
session.sendSpectateLocation();
}
} }
} }

View file

@ -44,5 +44,9 @@ public class JavaEntityPositionTranslator extends PacketTranslator<ServerEntityP
if (entity == null) return; if (entity == null) return;
entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation(), packet.isOnGround()); entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation(), packet.isOnGround());
if (session.getSpectatingEntity() != null && session.getSpectatingEntity().getGeyserId() == entity.getGeyserId()) {
session.sendSpectateLocation();
}
} }
} }

View file

@ -83,6 +83,7 @@ public class JavaSpawnEntityTranslator extends PacketTranslator<ServerSpawnEntit
type, position, motion, rotation type, position, motion, rotation
); );
} }
entity.setJavaUuid(packet.getUuid());
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace(); ex.printStackTrace();

View file

@ -61,6 +61,7 @@ public class JavaSpawnLivingEntityTranslator extends PacketTranslator<ServerSpaw
Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(),
type, position, motion, rotation type, position, motion, rotation
); );
entity.setJavaUuid(packet.getUuid());
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace(); ex.printStackTrace();

View file

@ -51,6 +51,7 @@ public class JavaSpawnPaintingTranslator extends PacketTranslator<ServerSpawnPai
.setPaintingName(PaintingType.getByPaintingType(packet.getPaintingType())) .setPaintingName(PaintingType.getByPaintingType(packet.getPaintingType()))
.setDirection(packet.getDirection().ordinal()); .setDirection(packet.getDirection().ordinal());
entity.setJavaUuid(packet.getUuid());
session.getEntityCache().spawnEntity(entity); session.getEntityCache().spawnEntity(entity);
}); });
} }

View file

@ -50,6 +50,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlaye
} }
entity.setEntityId(packet.getEntityId()); entity.setEntityId(packet.getEntityId());
entity.setJavaUuid(packet.getUuid());
entity.setPosition(position); entity.setPosition(position);
entity.setRotation(rotation); entity.setRotation(rotation);
session.getEntityCache().cacheEntity(entity); session.getEntityCache().cacheEntity(entity);