Compare commits

...

2 Commits

Author SHA1 Message Date
Luke 116dea9cb6
Remove some debug 2020-09-26 02:45:31 +01:00
Luke 4bbb057f62
Get the basics working 2020-09-26 02:37:13 +01:00
11 changed files with 127 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.MessageUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Getter
@Setter
@ -67,6 +64,8 @@ public class Entity {
protected long entityId;
protected long geyserId;
protected UUID javaUuid;
protected String dimension;
protected Vector3f position;

View File

@ -47,6 +47,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.data.*;
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
import com.nukkitx.protocol.bedrock.data.entity.EntityLinkData;
import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
@ -261,6 +262,11 @@ public class GeyserSession implements CommandSender {
@Setter
private String lastSignMessage;
private Entity spectatingEntity = null;
private Vector3f originalPosition = null;
private Vector3f originalRotation = null;
private boolean originalOnGround = false;
private MinecraftProtocol protocol;
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession) {
@ -751,4 +757,44 @@ public class GeyserSession implements CommandSender {
adventureSettingsPacket.getSettings().addAll(flags);
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());
}
}

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.ClientPlayerPlaceBlockPacket;
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.Vector3i;
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.InventoryTransactionPacket;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.CommandBlockMinecartEntity;
import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.ItemFrameEntity;
@ -242,6 +244,15 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
//https://wiki.vg/Protocol#Interact_Entity
switch (packet.getActionType()) {
case 0: //Interact
if (session.getGameMode() == GameMode.SPECTATOR) {
if (entity.getJavaUuid() == null) {
GeyserConnector.getInstance().getLogger().debug("Tried to spectate entity with no Java UUID");
return;
}
session.sendDownstreamPacket(new ClientSpectatePacket(entity.getJavaUuid()));
return;
}
if (entity instanceof CommandBlockMinecartEntity) {
// The UI is handled client-side on Java Edition
// Ensure OP permission level and gamemode is appropriate

View File

@ -25,6 +25,7 @@
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.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;

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;
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;
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
);
}
entity.setJavaUuid(packet.getUuid());
session.getEntityCache().spawnEntity(entity);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();

View File

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

View File

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

View File

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