Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Merge remote-tracking branch 'remotes/upstream/master' into inventory
# Conflicts: # connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java # connector/src/main/java/org/geysermc/connector/network/translators/inventory/updater/ChestInventoryUpdater.java
Dieser Commit ist enthalten in:
Commit
bc3992f775
@ -11,9 +11,9 @@ Geyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Editio
|
|||||||
|
|
||||||
## What is Geyser?
|
## What is Geyser?
|
||||||
Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers.
|
Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers.
|
||||||
The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible.
|
The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible. **Please note, this project is still a work in progress and should not be used on production. Expect bugs!**
|
||||||
|
|
||||||
### Please note, this project is still a work in progress and should not be used on production. Expect bugs!
|
### Currently supporting Minecraft Bedrock v1.14.X and Minecraft Java v1.15.2.
|
||||||
|
|
||||||
## Setting Up
|
## Setting Up
|
||||||
Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up.
|
Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up.
|
||||||
@ -35,7 +35,6 @@ Please note, Geyser is **not** (currently) a plugin. Watch the video below or ta
|
|||||||
- Block Particles
|
- Block Particles
|
||||||
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
|
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
|
||||||
- Some Entity Flags
|
- Some Entity Flags
|
||||||
- Proper Movement
|
|
||||||
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
|
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
|
||||||
|
|
||||||
## Compiling
|
## Compiling
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.nukkitx.protocol</groupId>
|
<groupId>com.nukkitx.protocol</groupId>
|
||||||
<artifactId>bedrock-v389</artifactId>
|
<artifactId>bedrock-v389</artifactId>
|
||||||
<version>2.4.4</version>
|
<version>2.5.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -30,7 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
|
|||||||
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
import com.github.steveice10.mc.protocol.data.message.TextMessage;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlags;
|
import com.nukkitx.protocol.bedrock.data.EntityFlags;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
@ -65,7 +65,6 @@ public class Entity {
|
|||||||
protected Vector3f rotation;
|
protected Vector3f rotation;
|
||||||
|
|
||||||
protected float scale = 1;
|
protected float scale = 1;
|
||||||
protected boolean movePending;
|
|
||||||
|
|
||||||
protected EntityType entityType;
|
protected EntityType entityType;
|
||||||
|
|
||||||
@ -73,20 +72,20 @@ public class Entity {
|
|||||||
|
|
||||||
protected LongSet passengers = new LongOpenHashSet();
|
protected LongSet passengers = new LongOpenHashSet();
|
||||||
protected Map<AttributeType, Attribute> attributes = new HashMap<>();
|
protected Map<AttributeType, Attribute> attributes = new HashMap<>();
|
||||||
protected EntityDataDictionary metadata = new EntityDataDictionary();
|
protected EntityDataMap metadata = new EntityDataMap();
|
||||||
|
|
||||||
public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public Entity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
this.geyserId = geyserId;
|
this.geyserId = geyserId;
|
||||||
this.entityType = entityType;
|
this.entityType = entityType;
|
||||||
this.position = position;
|
|
||||||
this.motion = motion;
|
this.motion = motion;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
|
|
||||||
this.valid = false;
|
this.valid = false;
|
||||||
this.movePending = false;
|
|
||||||
this.dimension = 0;
|
this.dimension = 0;
|
||||||
|
|
||||||
|
setPosition(position);
|
||||||
|
|
||||||
metadata.put(EntityData.SCALE, 1f);
|
metadata.put(EntityData.SCALE, 1f);
|
||||||
metadata.put(EntityData.MAX_AIR, (short) 400);
|
metadata.put(EntityData.MAX_AIR, (short) 400);
|
||||||
metadata.put(EntityData.AIR, (short) 0);
|
metadata.put(EntityData.AIR, (short) 0);
|
||||||
@ -132,28 +131,45 @@ public class Entity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch) {
|
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {
|
||||||
moveRelative(relX, relY, relZ, Vector3f.from(yaw, pitch, yaw));
|
moveRelative(session, relX, relY, relZ, Vector3f.from(yaw, pitch, yaw), isOnGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) {
|
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
||||||
this.movePending = true;
|
|
||||||
|
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||||
|
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||||
|
moveEntityPacket.setPosition(position);
|
||||||
|
moveEntityPacket.setRotation(getBedrockRotation());
|
||||||
|
moveEntityPacket.setOnGround(isOnGround);
|
||||||
|
moveEntityPacket.setTeleported(false);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(moveEntityPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveAbsolute(Vector3f position, float yaw, float pitch) {
|
public void moveAbsolute(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround) {
|
||||||
moveAbsolute(position, Vector3f.from(yaw, pitch, yaw));
|
moveAbsolute(session, position, Vector3f.from(yaw, pitch, yaw), isOnGround);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveAbsolute(Vector3f position, Vector3f rotation) {
|
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
|
|
||||||
this.movePending = true;
|
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||||
|
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||||
|
moveEntityPacket.setPosition(position);
|
||||||
|
moveEntityPacket.setRotation(getBedrockRotation());
|
||||||
|
moveEntityPacket.setOnGround(isOnGround);
|
||||||
|
moveEntityPacket.setTeleported(false);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(moveEntityPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBedrockAttributes(GeyserSession session) {
|
public void updateBedrockAttributes(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>();
|
List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>();
|
||||||
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
|
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
|
||||||
if (!entry.getValue().getType().isBedrockAttribute())
|
if (!entry.getValue().getType().isBedrockAttribute())
|
||||||
@ -180,7 +196,7 @@ public class Entity {
|
|||||||
metadata.getFlags().setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80);
|
metadata.getFlags().setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80);
|
||||||
// metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
|
// metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
|
||||||
if ((xd & 0x20) == 0x20)
|
if ((xd & 0x20) == 0x20)
|
||||||
metadata.put(EntityData.SCALE, 0.01f);
|
metadata.put(EntityData.SCALE, 0.0f);
|
||||||
else
|
else
|
||||||
metadata.put(EntityData.SCALE, scale);
|
metadata.put(EntityData.SCALE, scale);
|
||||||
}
|
}
|
||||||
@ -191,7 +207,8 @@ public class Entity {
|
|||||||
metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name));
|
metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name));
|
||||||
break;
|
break;
|
||||||
case 3: // is custom name visible
|
case 3: // is custom name visible
|
||||||
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
|
if (!this.is(PlayerEntity.class))
|
||||||
|
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
|
||||||
break;
|
break;
|
||||||
case 4: // silent
|
case 4: // silent
|
||||||
metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue());
|
metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue());
|
||||||
@ -201,20 +218,18 @@ public class Entity {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateBedrockMetadata(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateBedrockMetadata(GeyserSession session) {
|
||||||
|
if (!valid) return;
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
entityDataPacket.setRuntimeEntityId(geyserId);
|
entityDataPacket.setRuntimeEntityId(geyserId);
|
||||||
entityDataPacket.getMetadata().putAll(metadata);
|
entityDataPacket.getMetadata().putAll(metadata);
|
||||||
session.getUpstream().sendPacket(entityDataPacket);
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(Vector3f position) {
|
|
||||||
if (is(PlayerEntity.class)) {
|
|
||||||
this.position = position.add(0, entityType.getOffset(), 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* x = Pitch, y = HeadYaw, z = Yaw
|
* x = Pitch, y = HeadYaw, z = Yaw
|
||||||
*/
|
*/
|
||||||
|
@ -27,6 +27,7 @@ package org.geysermc.connector.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityData;
|
import com.nukkitx.protocol.bedrock.data.EntityData;
|
||||||
import com.nukkitx.protocol.bedrock.data.ItemData;
|
import com.nukkitx.protocol.bedrock.data.ItemData;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
|
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
|
||||||
@ -42,11 +43,12 @@ import org.geysermc.connector.network.session.GeyserSession;
|
|||||||
@Setter
|
@Setter
|
||||||
public class LivingEntity extends Entity {
|
public class LivingEntity extends Entity {
|
||||||
|
|
||||||
protected ItemData helmet;
|
protected ItemData helmet = ItemData.AIR;
|
||||||
protected ItemData chestplate;
|
protected ItemData chestplate = ItemData.AIR;
|
||||||
protected ItemData leggings;
|
protected ItemData leggings = ItemData.AIR;
|
||||||
protected ItemData boots;
|
protected ItemData boots = ItemData.AIR;
|
||||||
protected ItemData hand = ItemData.of(0, (short) 0, 0);
|
protected ItemData hand = ItemData.AIR;
|
||||||
|
protected ItemData offHand = ItemData.AIR;
|
||||||
|
|
||||||
public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
|
||||||
super(entityId, geyserId, entityType, position, motion, rotation);
|
super(entityId, geyserId, entityType, position, motion, rotation);
|
||||||
@ -80,11 +82,22 @@ public class LivingEntity extends Entity {
|
|||||||
armorEquipmentPacket.setLeggings(leggings);
|
armorEquipmentPacket.setLeggings(leggings);
|
||||||
armorEquipmentPacket.setBoots(boots);
|
armorEquipmentPacket.setBoots(boots);
|
||||||
|
|
||||||
MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket();
|
MobEquipmentPacket handPacket = new MobEquipmentPacket();
|
||||||
mobEquipmentPacket.setRuntimeEntityId(geyserId);
|
handPacket.setRuntimeEntityId(geyserId);
|
||||||
mobEquipmentPacket.setItem(hand);
|
handPacket.setItem(hand);
|
||||||
|
handPacket.setHotbarSlot(-1);
|
||||||
|
handPacket.setInventorySlot(0);
|
||||||
|
handPacket.setContainerId(ContainerId.INVENTORY);
|
||||||
|
|
||||||
|
MobEquipmentPacket offHandPacket = new MobEquipmentPacket();
|
||||||
|
offHandPacket.setRuntimeEntityId(geyserId);
|
||||||
|
offHandPacket.setItem(offHand);
|
||||||
|
offHandPacket.setHotbarSlot(-1);
|
||||||
|
offHandPacket.setInventorySlot(0);
|
||||||
|
offHandPacket.setContainerId(ContainerId.OFFHAND);
|
||||||
|
|
||||||
session.getUpstream().sendPacket(armorEquipmentPacket);
|
session.getUpstream().sendPacket(armorEquipmentPacket);
|
||||||
session.getUpstream().sendPacket(mobEquipmentPacket);
|
session.getUpstream().sendPacket(handPacket);
|
||||||
|
session.getUpstream().sendPacket(offHandPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,10 @@ package org.geysermc.connector.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.auth.data.GameProfile;
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.CommandPermission;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -74,24 +77,24 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
addPlayerPacket.setRotation(getBedrockRotation());
|
addPlayerPacket.setRotation(getBedrockRotation());
|
||||||
addPlayerPacket.setMotion(motion);
|
addPlayerPacket.setMotion(motion);
|
||||||
addPlayerPacket.setHand(hand);
|
addPlayerPacket.setHand(hand);
|
||||||
addPlayerPacket.setPlayerFlags(0);
|
addPlayerPacket.getAdventureSettings().setCommandPermission(CommandPermission.NORMAL);
|
||||||
addPlayerPacket.setCommandPermission(0);
|
addPlayerPacket.getAdventureSettings().setPlayerPermission(PlayerPermission.VISITOR);
|
||||||
addPlayerPacket.setWorldFlags(0);
|
|
||||||
addPlayerPacket.setPlayerPermission(0);
|
|
||||||
addPlayerPacket.setCustomFlags(0);
|
|
||||||
addPlayerPacket.setDeviceId("");
|
addPlayerPacket.setDeviceId("");
|
||||||
addPlayerPacket.setPlatformChatId("");
|
addPlayerPacket.setPlatformChatId("");
|
||||||
addPlayerPacket.getMetadata().putAll(getMetadata());
|
addPlayerPacket.getMetadata().putAll(metadata);
|
||||||
|
|
||||||
valid = true;
|
valid = true;
|
||||||
session.getUpstream().sendPacket(addPlayerPacket);
|
session.getUpstream().sendPacket(addPlayerPacket);
|
||||||
|
|
||||||
|
updateEquipment(session);
|
||||||
|
updateBedrockAttributes(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayer(GeyserSession session) {
|
public void sendPlayer(GeyserSession session) {
|
||||||
if (getLastSkinUpdate() == -1) {
|
if (getLastSkinUpdate() == -1) {
|
||||||
if (playerList) {
|
if (playerList) {
|
||||||
PlayerListPacket playerList = new PlayerListPacket();
|
PlayerListPacket playerList = new PlayerListPacket();
|
||||||
playerList.setType(PlayerListPacket.Type.ADD);
|
playerList.setAction(PlayerListPacket.Action.ADD);
|
||||||
playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId));
|
playerList.getEntries().add(SkinUtils.buildDefaultEntry(profile, geyserId));
|
||||||
session.getUpstream().sendPacket(playerList);
|
session.getUpstream().sendPacket(playerList);
|
||||||
}
|
}
|
||||||
@ -107,10 +110,44 @@ public class PlayerEntity extends LivingEntity {
|
|||||||
// remove from playerlist if player isn't on playerlist
|
// remove from playerlist if player isn't on playerlist
|
||||||
Geyser.getGeneralThreadPool().execute(() -> {
|
Geyser.getGeneralThreadPool().execute(() -> {
|
||||||
PlayerListPacket playerList = new PlayerListPacket();
|
PlayerListPacket playerList = new PlayerListPacket();
|
||||||
playerList.setType(PlayerListPacket.Type.REMOVE);
|
playerList.setAction(PlayerListPacket.Action.REMOVE);
|
||||||
playerList.getEntries().add(new PlayerListPacket.Entry(uuid));
|
playerList.getEntries().add(new PlayerListPacket.Entry(uuid));
|
||||||
session.getUpstream().sendPacket(playerList);
|
session.getUpstream().sendPacket(playerList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) {
|
||||||
|
setPosition(position);
|
||||||
|
setRotation(rotation);
|
||||||
|
|
||||||
|
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||||
|
movePlayerPacket.setRuntimeEntityId(geyserId);
|
||||||
|
movePlayerPacket.setPosition(this.position);
|
||||||
|
movePlayerPacket.setRotation(getBedrockRotation());
|
||||||
|
movePlayerPacket.setOnGround(isOnGround);
|
||||||
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||||
|
|
||||||
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||||
|
setRotation(rotation);
|
||||||
|
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
||||||
|
|
||||||
|
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||||
|
movePlayerPacket.setRuntimeEntityId(geyserId);
|
||||||
|
movePlayerPacket.setPosition(position);
|
||||||
|
movePlayerPacket.setRotation(getBedrockRotation());
|
||||||
|
movePlayerPacket.setOnGround(isOnGround);
|
||||||
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||||
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPosition(Vector3f position) {
|
||||||
|
this.position = position.add(0, entityType.getOffset(), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ public class ArmorStandEntity extends LivingEntity {
|
|||||||
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
|
||||||
if (entityMetadata.getType() == MetadataType.BYTE) {
|
if (entityMetadata.getType() == MetadataType.BYTE) {
|
||||||
byte xd = (byte) entityMetadata.getValue();
|
byte xd = (byte) entityMetadata.getValue();
|
||||||
if((xd & 0x01) == 0x01) {
|
if ((xd & 0x01) == 0x01 && (metadata.get(EntityData.SCALE) != null && !metadata.get(EntityData.SCALE).equals(0.0f))) {
|
||||||
metadata.put(EntityData.SCALE, .55f);
|
metadata.put(EntityData.SCALE, .55f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,11 +192,6 @@ public class LoggingPacketHandler implements BedrockPacketHandler {
|
|||||||
return defaultHandler(packet);
|
return defaultHandler(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(LevelSoundEvent3Packet packet) {
|
|
||||||
return defaultHandler(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(MapInfoRequestPacket packet) {
|
public boolean handle(MapInfoRequestPacket packet) {
|
||||||
return defaultHandler(packet);
|
return defaultHandler(packet);
|
||||||
|
@ -37,17 +37,17 @@ import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
|
|||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
|
import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
|
||||||
|
import com.nukkitx.math.GenericMath;
|
||||||
|
import com.nukkitx.math.TrigMath;
|
||||||
import com.nukkitx.math.vector.Vector2f;
|
import com.nukkitx.math.vector.Vector2f;
|
||||||
import com.nukkitx.math.vector.Vector2i;
|
|
||||||
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.nbt.NbtUtils;
|
|
||||||
import com.nukkitx.nbt.stream.NBTInputStream;
|
|
||||||
import com.nukkitx.nbt.tag.CompoundTag;
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||||
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
import com.nukkitx.protocol.bedrock.data.ContainerId;
|
||||||
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
||||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
import com.nukkitx.protocol.bedrock.data.GameRuleData;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -56,7 +56,6 @@ import org.geysermc.api.RemoteServer;
|
|||||||
import org.geysermc.api.session.AuthData;
|
import org.geysermc.api.session.AuthData;
|
||||||
import org.geysermc.api.window.FormWindow;
|
import org.geysermc.api.window.FormWindow;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.console.GeyserLogger;
|
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.inventory.PlayerInventory;
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.cache.*;
|
import org.geysermc.connector.network.session.cache.*;
|
||||||
@ -65,9 +64,9 @@ import org.geysermc.connector.network.translators.block.BlockTranslator;
|
|||||||
import org.geysermc.connector.utils.ChunkUtils;
|
import org.geysermc.connector.utils.ChunkUtils;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class GeyserSession implements Player {
|
public class GeyserSession implements Player {
|
||||||
@ -89,9 +88,6 @@ public class GeyserSession implements Player {
|
|||||||
|
|
||||||
private DataCache<Packet> javaPacketCache;
|
private DataCache<Packet> javaPacketCache;
|
||||||
|
|
||||||
@Setter
|
|
||||||
private Vector2i lastChunkPosition = null;
|
|
||||||
@Setter
|
|
||||||
private int renderDistance;
|
private int renderDistance;
|
||||||
|
|
||||||
private boolean loggedIn;
|
private boolean loggedIn;
|
||||||
@ -104,6 +100,13 @@ public class GeyserSession implements Player {
|
|||||||
@Setter
|
@Setter
|
||||||
private GameMode gameMode = GameMode.SURVIVAL;
|
private GameMode gameMode = GameMode.SURVIVAL;
|
||||||
|
|
||||||
|
private final AtomicInteger pendingDimSwitches = new AtomicInteger(0);
|
||||||
|
@Setter
|
||||||
|
private boolean sprinting;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private boolean jumping;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private boolean switchingDimension = false;
|
private boolean switchingDimension = false;
|
||||||
private boolean manyDimPackets = false;
|
private boolean manyDimPackets = false;
|
||||||
@ -136,6 +139,10 @@ public class GeyserSession implements Player {
|
|||||||
public void connect(RemoteServer remoteServer) {
|
public void connect(RemoteServer remoteServer) {
|
||||||
startGame();
|
startGame();
|
||||||
this.remoteServer = remoteServer;
|
this.remoteServer = remoteServer;
|
||||||
|
if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
||||||
|
connector.getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
||||||
|
authenticate(authenticationData.getName());
|
||||||
|
}
|
||||||
|
|
||||||
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
||||||
|
|
||||||
@ -279,6 +286,16 @@ public class GeyserSession implements Player {
|
|||||||
windowCache.showWindow(window, id);
|
windowCache.showWindow(window, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setRenderDistance(int renderDistance) {
|
||||||
|
renderDistance = GenericMath.ceil(++renderDistance * TrigMath.SQRT_OF_TWO); //square to circle
|
||||||
|
if (renderDistance > 32) renderDistance = 32; // <3 u ViaVersion but I don't like crashing clients x)
|
||||||
|
this.renderDistance = renderDistance;
|
||||||
|
|
||||||
|
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
|
||||||
|
chunkRadiusUpdatedPacket.setRadius(renderDistance);
|
||||||
|
upstream.sendPacket(chunkRadiusUpdatedPacket);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getSocketAddress() {
|
public InetSocketAddress getSocketAddress() {
|
||||||
return this.upstream.getAddress();
|
return this.upstream.getAddress();
|
||||||
@ -310,7 +327,7 @@ public class GeyserSession implements Player {
|
|||||||
startGamePacket.setLightningLevel(0);
|
startGamePacket.setLightningLevel(0);
|
||||||
startGamePacket.setMultiplayerGame(true);
|
startGamePacket.setMultiplayerGame(true);
|
||||||
startGamePacket.setBroadcastingToLan(true);
|
startGamePacket.setBroadcastingToLan(true);
|
||||||
startGamePacket.getGamerules().add(new GameRule<>("showcoordinates", true));
|
startGamePacket.getGamerules().add(new GameRuleData<>("showcoordinates", true));
|
||||||
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
|
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
|
||||||
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
|
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
|
||||||
startGamePacket.setCommandsEnabled(true);
|
startGamePacket.setCommandsEnabled(true);
|
||||||
@ -318,7 +335,7 @@ public class GeyserSession implements Player {
|
|||||||
startGamePacket.setBonusChestEnabled(false);
|
startGamePacket.setBonusChestEnabled(false);
|
||||||
startGamePacket.setStartingWithMap(false);
|
startGamePacket.setStartingWithMap(false);
|
||||||
startGamePacket.setTrustingPlayers(true);
|
startGamePacket.setTrustingPlayers(true);
|
||||||
startGamePacket.setDefaultPlayerPermission(1);
|
startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
startGamePacket.setServerChunkTickRange(4);
|
startGamePacket.setServerChunkTickRange(4);
|
||||||
startGamePacket.setBehaviorPackLocked(false);
|
startGamePacket.setBehaviorPackLocked(false);
|
||||||
startGamePacket.setResourcePackLocked(false);
|
startGamePacket.setResourcePackLocked(false);
|
||||||
|
@ -55,10 +55,13 @@ public class EntityCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void spawnEntity(Entity entity) {
|
public void spawnEntity(Entity entity) {
|
||||||
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
|
cacheEntity(entity);
|
||||||
|
entity.spawnEntity(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cacheEntity(Entity entity) {
|
||||||
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
|
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
|
||||||
entities.put(entity.getGeyserId(), entity);
|
entities.put(entity.getGeyserId(), entity);
|
||||||
entity.spawnEntity(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeEntity(Entity entity, boolean force) {
|
public boolean removeEntity(Entity entity, boolean force) {
|
||||||
|
@ -128,8 +128,7 @@ public class TranslatorsInit {
|
|||||||
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
Registry.registerJava(ServerPlayerActionAckPacket.class, new JavaPlayerActionAckTranslator());
|
||||||
Registry.registerJava(ServerPlayerChangeHeldItemPacket.class, new JavaPlayerChangeHeldItemTranslator());
|
Registry.registerJava(ServerPlayerChangeHeldItemPacket.class, new JavaPlayerChangeHeldItemTranslator());
|
||||||
|
|
||||||
// FIXME: This translator messes with allowing flight in creative mode. Will need to be addressed later
|
Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
||||||
// Registry.registerJava(ServerPlayerAbilitiesPacket.class, new JavaPlayerAbilitiesTranslator());
|
|
||||||
|
|
||||||
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
||||||
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunkDataTranslator());
|
||||||
@ -149,6 +148,9 @@ public class TranslatorsInit {
|
|||||||
Registry.registerJava(ServerConfirmTransactionPacket.class, new JavaConfirmTransactionTranslator());
|
Registry.registerJava(ServerConfirmTransactionPacket.class, new JavaConfirmTransactionTranslator());
|
||||||
Registry.registerJava(ServerWindowPropertyPacket.class, new JavaWindowPropertyTranslator());
|
Registry.registerJava(ServerWindowPropertyPacket.class, new JavaWindowPropertyTranslator());
|
||||||
|
|
||||||
|
Registry.registerJava(ServerUpdateViewPositionPacket.class, new JavaUpdateViewPositionTranslator());
|
||||||
|
Registry.registerJava(ServerUpdateViewDistancePacket.class, new JavaUpdateViewDistanceTranslator());
|
||||||
|
|
||||||
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator());
|
||||||
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
Registry.registerBedrock(CommandRequestPacket.class, new BedrockCommandRequestTranslator());
|
||||||
Registry.registerBedrock(InventoryTransactionPacket.class, new BedrockInventoryTransactionTranslator());
|
Registry.registerBedrock(InventoryTransactionPacket.class, new BedrockInventoryTransactionTranslator());
|
||||||
|
@ -40,6 +40,8 @@ import org.geysermc.connector.entity.Entity;
|
|||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,6 +58,14 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
// Don't put anything here as respawn is already handled
|
// Don't put anything here as respawn is already handled
|
||||||
// in BedrockRespawnTranslator
|
// in BedrockRespawnTranslator
|
||||||
break;
|
break;
|
||||||
|
case START_SWIMMING:
|
||||||
|
ClientPlayerStatePacket startSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||||
|
session.getDownstream().getSession().send(startSwimPacket);
|
||||||
|
break;
|
||||||
|
case STOP_SWIMMING:
|
||||||
|
ClientPlayerStatePacket stopSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||||
|
session.getDownstream().getSession().send(stopSwimPacket);
|
||||||
|
break;
|
||||||
case START_GLIDE:
|
case START_GLIDE:
|
||||||
case STOP_GLIDE:
|
case STOP_GLIDE:
|
||||||
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
||||||
@ -72,10 +82,12 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
case START_SPRINT:
|
case START_SPRINT:
|
||||||
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||||
session.getDownstream().getSession().send(startSprintPacket);
|
session.getDownstream().getSession().send(startSprintPacket);
|
||||||
|
session.setSprinting(true);
|
||||||
break;
|
break;
|
||||||
case STOP_SPRINT:
|
case STOP_SPRINT:
|
||||||
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||||
session.getDownstream().getSession().send(stopSprintPacket);
|
session.getDownstream().getSession().send(stopSprintPacket);
|
||||||
|
session.setSprinting(false);
|
||||||
break;
|
break;
|
||||||
case DROP_ITEM:
|
case DROP_ITEM:
|
||||||
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
||||||
@ -107,12 +119,19 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||||||
// Handled in BedrockInventoryTransactionTranslator
|
// Handled in BedrockInventoryTransactionTranslator
|
||||||
break;
|
break;
|
||||||
case DIMENSION_CHANGE_SUCCESS:
|
case DIMENSION_CHANGE_SUCCESS:
|
||||||
session.setSwitchingDimension(false);
|
if (session.getPendingDimSwitches().decrementAndGet() == 0) {
|
||||||
//sometimes the client doesn't feel like loading
|
//sometimes the client doesn't feel like loading
|
||||||
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
||||||
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||||
session.getUpstream().sendPacket(spawnPacket);
|
session.getUpstream().sendPacket(spawnPacket);
|
||||||
entity.updateBedrockAttributes(session);
|
entity.updateBedrockAttributes(session);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case JUMP:
|
||||||
|
session.setJumping(true);
|
||||||
|
session.getConnector().getGeneralThreadPool().schedule(() -> {
|
||||||
|
session.setJumping(false);
|
||||||
|
}, 1, TimeUnit.SECONDS);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,12 +44,12 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case 1:
|
case INTERACT:
|
||||||
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
InteractAction.INTERACT, Hand.MAIN_HAND);
|
InteractAction.INTERACT, Hand.MAIN_HAND);
|
||||||
session.getDownstream().getSession().send(interactPacket);
|
session.getDownstream().getSession().send(interactPacket);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case DAMAGE:
|
||||||
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
InteractAction.ATTACK, Hand.MAIN_HAND);
|
InteractAction.ATTACK, Hand.MAIN_HAND);
|
||||||
session.getDownstream().getSession().send(attackPacket);
|
session.getDownstream().getSession().send(attackPacket);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package org.geysermc.connector.network.translators.bedrock;
|
package org.geysermc.connector.network.translators.bedrock;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
||||||
|
import com.nukkitx.math.GenericMath;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||||
@ -42,7 +43,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
@Override
|
@Override
|
||||||
public void translate(MovePlayerPacket packet, GeyserSession session) {
|
public void translate(MovePlayerPacket packet, GeyserSession session) {
|
||||||
PlayerEntity entity = session.getPlayerEntity();
|
PlayerEntity entity = session.getPlayerEntity();
|
||||||
if (entity == null || !session.isSpawned() || session.isSwitchingDimension()) return;
|
if (entity == null || !session.isSpawned() || session.getPendingDimSwitches().get() > 0) return;
|
||||||
|
|
||||||
if (!session.getUpstream().isInitialized()) {
|
if (!session.getUpstream().isInitialized()) {
|
||||||
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
||||||
@ -62,16 +63,15 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
}
|
}
|
||||||
|
|
||||||
double javaY = packet.getPosition().getY() - EntityType.PLAYER.getOffset();
|
double javaY = packet.getPosition().getY() - EntityType.PLAYER.getOffset();
|
||||||
|
if (packet.isOnGround()) javaY = Math.ceil(javaY * 2) / 2;
|
||||||
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
|
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
|
||||||
packet.isOnGround(), packet.getPosition().getX(), javaY,
|
packet.isOnGround(), GenericMath.round(packet.getPosition().getX(), 4), javaY, GenericMath.round(packet.getPosition().getZ(), 4), packet.getRotation().getY(), packet.getRotation().getX()
|
||||||
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// head yaw, pitch, head yaw
|
// head yaw, pitch, head yaw
|
||||||
Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY());
|
Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY());
|
||||||
|
entity.setPosition(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0));
|
||||||
entity.moveAbsolute(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0), rotation);
|
entity.setRotation(rotation);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
boolean colliding = false;
|
boolean colliding = false;
|
||||||
@ -124,8 +124,6 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||||||
movePlayerPacket.setPosition(entity.getPosition());
|
movePlayerPacket.setPosition(entity.getPosition());
|
||||||
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||||
movePlayerPacket.setOnGround(true);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
session.getUpstream().sendPacket(movePlayerPacket);
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,11 +38,6 @@ public class BedrockPlayerInitializedTranslator extends PacketTranslator<SetLoca
|
|||||||
if (!session.getUpstream().isInitialized()) {
|
if (!session.getUpstream().isInitialized()) {
|
||||||
session.getUpstream().setInitialized(true);
|
session.getUpstream().setInitialized(true);
|
||||||
|
|
||||||
if (!(session.getConnector().getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) {
|
|
||||||
session.getConnector().getLogger().info("Attempting to login using offline mode... authentication is disabled.");
|
|
||||||
session.authenticate(session.getAuthenticationData().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) {
|
for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) {
|
||||||
if (!entity.isValid()) {
|
if (!entity.isValid()) {
|
||||||
// async skin loading
|
// async skin loading
|
||||||
|
@ -36,11 +36,11 @@ public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(RespawnPacket packet, GeyserSession session) {
|
public void translate(RespawnPacket packet, GeyserSession session) {
|
||||||
if (packet.getSpawnState() == RespawnPacket.State.CLIENT_READY) {
|
if (packet.getState() == RespawnPacket.State.CLIENT_READY) {
|
||||||
RespawnPacket respawnPacket = new RespawnPacket();
|
RespawnPacket respawnPacket = new RespawnPacket();
|
||||||
respawnPacket.setRuntimeEntityId(0);
|
respawnPacket.setRuntimeEntityId(0);
|
||||||
respawnPacket.setPosition(Vector3f.ZERO);
|
respawnPacket.setPosition(Vector3f.ZERO);
|
||||||
respawnPacket.setSpawnState(RespawnPacket.State.SERVER_SEARCHING);
|
respawnPacket.setState(RespawnPacket.State.SERVER_SEARCHING);
|
||||||
session.getUpstream().sendPacket(respawnPacket);
|
session.getUpstream().sendPacket(respawnPacket);
|
||||||
|
|
||||||
ClientRequestPacket javaRespawnPacket = new ClientRequestPacket(ClientRequest.RESPAWN);
|
ClientRequestPacket javaRespawnPacket = new ClientRequestPacket(ClientRequest.RESPAWN);
|
||||||
|
@ -67,7 +67,7 @@ public class BlockTranslator {
|
|||||||
Map<CompoundTag, CompoundTag> blockStateMap = new HashMap<>();
|
Map<CompoundTag, CompoundTag> blockStateMap = new HashMap<>();
|
||||||
|
|
||||||
for (CompoundTag tag : blocksTag.getValue()) {
|
for (CompoundTag tag : blocksTag.getValue()) {
|
||||||
if (blockStateMap.putIfAbsent(tag.getAsCompound("block"), tag) != null) {
|
if (blockStateMap.putIfAbsent(tag.getCompound("block"), tag) != null) {
|
||||||
throw new AssertionError("Duplicate block states in Bedrock palette");
|
throw new AssertionError("Duplicate block states in Bedrock palette");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||||||
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
long entityId = session.getEntityCache().addBossBar(packet.getUuid());
|
||||||
addBossEntity(session, entityId);
|
addBossEntity(session, entityId);
|
||||||
|
|
||||||
bossEventPacket.setType(BossEventPacket.Type.SHOW);
|
bossEventPacket.setAction(BossEventPacket.Action.SHOW);
|
||||||
bossEventPacket.setBossUniqueEntityId(entityId);
|
bossEventPacket.setBossUniqueEntityId(entityId);
|
||||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||||
@ -55,15 +55,15 @@ public class JavaBossBarTranslator extends PacketTranslator<ServerBossBarPacket>
|
|||||||
bossEventPacket.setDarkenSky(0);
|
bossEventPacket.setDarkenSky(0);
|
||||||
break;
|
break;
|
||||||
case UPDATE_TITLE:
|
case UPDATE_TITLE:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.TITLE);
|
bossEventPacket.setAction(BossEventPacket.Action.TITLE);
|
||||||
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle()));
|
||||||
break;
|
break;
|
||||||
case UPDATE_HEALTH:
|
case UPDATE_HEALTH:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.HEALTH_PERCENTAGE);
|
bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE);
|
||||||
bossEventPacket.setHealthPercentage(packet.getHealth());
|
bossEventPacket.setHealthPercentage(packet.getHealth());
|
||||||
break;
|
break;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
bossEventPacket.setType(BossEventPacket.Type.HIDE);
|
bossEventPacket.setAction(BossEventPacket.Action.HIDE);
|
||||||
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
removeBossEntity(session, session.getEntityCache().removeBossBar(packet.getUuid()));
|
||||||
break;
|
break;
|
||||||
case UPDATE_STYLE:
|
case UPDATE_STYLE:
|
||||||
|
@ -27,10 +27,12 @@ package org.geysermc.connector.network.translators.java;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||||
|
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import org.geysermc.connector.entity.PlayerEntity;
|
import org.geysermc.connector.entity.PlayerEntity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
import org.geysermc.connector.utils.ChunkUtils;
|
||||||
import org.geysermc.connector.utils.DimensionUtils;
|
import org.geysermc.connector.utils.DimensionUtils;
|
||||||
|
|
||||||
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
|
public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacket> {
|
||||||
@ -42,7 +44,7 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||||||
|
|
||||||
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
||||||
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
||||||
bedrockPacket.setPlayerPermission(1);
|
bedrockPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
session.getUpstream().sendPacket(bedrockPacket);
|
session.getUpstream().sendPacket(bedrockPacket);
|
||||||
|
|
||||||
PlayStatusPacket playStatus = new PlayStatusPacket();
|
PlayStatusPacket playStatus = new PlayStatusPacket();
|
||||||
@ -59,15 +61,11 @@ public class JavaJoinGameTranslator extends PacketTranslator<ServerJoinGamePacke
|
|||||||
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
||||||
session.getUpstream().sendPacket(entityDataPacket);
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
|
|
||||||
session.setRenderDistance(packet.getViewDistance() + 1); // +1 to be sure it includes every chunk
|
session.setRenderDistance(packet.getViewDistance());
|
||||||
if (session.getRenderDistance() > 32) session.setRenderDistance(32); // <3 u ViaVersion but I don't like crashing clients x)
|
|
||||||
|
|
||||||
ChunkRadiusUpdatedPacket chunkRadiusPacket = new ChunkRadiusUpdatedPacket();
|
|
||||||
chunkRadiusPacket.setRadius(session.getRenderDistance());
|
|
||||||
session.getUpstream().sendPacket(chunkRadiusPacket);
|
|
||||||
|
|
||||||
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
|
if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
|
||||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
ChunkUtils.sendEmptyChunks(session, entity.getPosition().toInt(), 3, true);
|
||||||
|
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,15 @@ public class JavaRespawnTranslator extends PacketTranslator<ServerRespawnPacket>
|
|||||||
session.setGameMode(packet.getGamemode());
|
session.setGameMode(packet.getGamemode());
|
||||||
|
|
||||||
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
|
if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
|
||||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||||
} else {
|
} else {
|
||||||
// Handled in JavaPlayerPositionRotationTranslator
|
|
||||||
session.setSpawned(false);
|
|
||||||
if (session.isManyDimPackets()) { //reloading world
|
if (session.isManyDimPackets()) { //reloading world
|
||||||
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
|
int fakeDim = entity.getDimension() == 0 ? -1 : 0;
|
||||||
DimensionUtils.switchDimension(session, fakeDim, true);
|
DimensionUtils.switchDimension(session, fakeDim);
|
||||||
DimensionUtils.switchDimension(session, packet.getDimension(), false);
|
DimensionUtils.switchDimension(session, packet.getDimension());
|
||||||
|
} else {
|
||||||
|
// Handled in JavaPlayerPositionRotationTranslator
|
||||||
|
session.setSpawned(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator<ServerEntity
|
|||||||
livingEntity.setHand(item);
|
livingEntity.setHand(item);
|
||||||
break;
|
break;
|
||||||
case OFF_HAND:
|
case OFF_HAND:
|
||||||
// TODO: livingEntity.setOffHand(item);
|
livingEntity.setOffHand(item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
@ -45,12 +47,19 @@ public class JavaEntityHeadLookTranslator extends PacketTranslator<ServerEntityH
|
|||||||
|
|
||||||
entity.setRotation(Vector3f.from(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw()));
|
entity.setRotation(Vector3f.from(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw()));
|
||||||
|
|
||||||
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
if (entity.getEntityType() != EntityType.PLAYER) {
|
||||||
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
||||||
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
||||||
moveEntityAbsolutePacket.setOnGround(true);
|
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
||||||
|
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
||||||
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
} else {
|
||||||
|
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||||
|
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
|
movePlayerPacket.setPosition(entity.getPosition());
|
||||||
|
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||||
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.ROTATION);
|
||||||
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,8 @@ public class JavaEntityMetadataTranslator extends PacketTranslator<ServerEntityM
|
|||||||
}
|
}
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
if (entity.isValid()) {
|
for (EntityMetadata metadata : packet.getMetadata()) {
|
||||||
for (EntityMetadata metadata : packet.getMetadata()) {
|
entity.updateBedrockMetadata(metadata, session);
|
||||||
entity.updateBedrockMetadata(metadata, session);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
entity.spawnEntity(session);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package org.geysermc.connector.network.translators.java.entity;
|
package org.geysermc.connector.network.translators.java.entity;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
|
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.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
@ -41,18 +40,6 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator<Serve
|
|||||||
}
|
}
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch());
|
entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch(), packet.isOnGround());
|
||||||
|
|
||||||
if (entity.isMovePending()) {
|
|
||||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
|
||||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
moveEntityPacket.setPosition(entity.getPosition());
|
|
||||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
|
||||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
|
||||||
moveEntityPacket.setTeleported(false);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(moveEntityPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
package org.geysermc.connector.network.translators.java.entity;
|
package org.geysermc.connector.network.translators.java.entity;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
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.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
@ -41,18 +41,6 @@ public class JavaEntityPositionTranslator extends PacketTranslator<ServerEntityP
|
|||||||
}
|
}
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation());
|
entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation(), packet.isOnGround());
|
||||||
|
|
||||||
if (entity.isMovePending()) {
|
|
||||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
|
||||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
moveEntityPacket.setPosition(entity.getPosition());
|
|
||||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
|
||||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
|
||||||
moveEntityPacket.setTeleported(false);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(moveEntityPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class JavaEntityPropertiesTranslator extends PacketTranslator<ServerEntit
|
|||||||
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
|
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
|
||||||
entity = session.getPlayerEntity();
|
entity = session.getPlayerEntity();
|
||||||
}
|
}
|
||||||
if (entity == null || !entity.isValid()) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
for (Attribute attribute : packet.getAttributes()) {
|
for (Attribute attribute : packet.getAttributes()) {
|
||||||
switch (attribute.getType()) {
|
switch (attribute.getType()) {
|
||||||
|
@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
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.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
@ -45,14 +47,20 @@ public class JavaEntityRotationTranslator extends PacketTranslator<ServerEntityR
|
|||||||
// entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
|
// entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
|
||||||
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
|
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
|
||||||
|
|
||||||
if (entity.isMovePending()) {
|
if (entity.getEntityType() != EntityType.PLAYER) {
|
||||||
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
||||||
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
||||||
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
||||||
|
} else {
|
||||||
|
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||||
|
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
|
movePlayerPacket.setPosition(entity.getPosition());
|
||||||
|
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||||
|
movePlayerPacket.setOnGround(packet.isOnGround());
|
||||||
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.ROTATION);
|
||||||
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
package org.geysermc.connector.network.translators.java.entity;
|
package org.geysermc.connector.network.translators.java.entity;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityEventType;
|
||||||
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
@ -47,48 +48,48 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
|
|||||||
switch (packet.getStatus()) {
|
switch (packet.getStatus()) {
|
||||||
case LIVING_HURT:
|
case LIVING_HURT:
|
||||||
case LIVING_HURT_SWEET_BERRY_BUSH:
|
case LIVING_HURT_SWEET_BERRY_BUSH:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.HURT_ANIMATION);
|
entityEventPacket.setType(EntityEventType.HURT_ANIMATION);
|
||||||
break;
|
break;
|
||||||
case LIVING_DEATH:
|
case LIVING_DEATH:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.DEATH_ANIMATION);
|
entityEventPacket.setType(EntityEventType.DEATH_ANIMATION);
|
||||||
break;
|
break;
|
||||||
case WOLF_SHAKE_WATER:
|
case WOLF_SHAKE_WATER:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.SHAKE_WET);
|
entityEventPacket.setType(EntityEventType.SHAKE_WET);
|
||||||
break;
|
break;
|
||||||
case PLAYER_FINISH_USING_ITEM:
|
case PLAYER_FINISH_USING_ITEM:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.USE_ITEM);
|
entityEventPacket.setType(EntityEventType.USE_ITEM);
|
||||||
break;
|
break;
|
||||||
case FISHING_HOOK_PULL_PLAYER:
|
case FISHING_HOOK_PULL_PLAYER:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.FISH_HOOK_LURED);
|
entityEventPacket.setType(EntityEventType.FISH_HOOK_LURED);
|
||||||
break;
|
break;
|
||||||
case TAMEABLE_TAMING_FAILED:
|
case TAMEABLE_TAMING_FAILED:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.TAME_FAIL);
|
entityEventPacket.setType(EntityEventType.TAME_FAIL);
|
||||||
break;
|
break;
|
||||||
case TAMEABLE_TAMING_SUCCEEDED:
|
case TAMEABLE_TAMING_SUCCEEDED:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.TAME_SUCCESS);
|
entityEventPacket.setType(EntityEventType.TAME_SUCCESS);
|
||||||
case ZOMBIE_VILLAGER_CURE:
|
case ZOMBIE_VILLAGER_CURE:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.ZOMBIE_VILLAGER_CURE);
|
entityEventPacket.setType(EntityEventType.ZOMBIE_VILLAGER_CURE);
|
||||||
break;
|
break;
|
||||||
case ANIMAL_EMIT_HEARTS:
|
case ANIMAL_EMIT_HEARTS:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.LOVE_PARTICLES);
|
entityEventPacket.setType(EntityEventType.LOVE_PARTICLES);
|
||||||
break;
|
break;
|
||||||
case FIREWORK_EXPLODE:
|
case FIREWORK_EXPLODE:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.FIREWORK_PARTICLES);
|
entityEventPacket.setType(EntityEventType.FIREWORK_PARTICLES);
|
||||||
break;
|
break;
|
||||||
case WITCH_EMIT_PARTICLES:
|
case WITCH_EMIT_PARTICLES:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.WITCH_SPELL_PARTICLES);
|
entityEventPacket.setType(EntityEventType.WITCH_SPELL_PARTICLES);
|
||||||
break;
|
break;
|
||||||
case TOTEM_OF_UNDYING_MAKE_SOUND:
|
case TOTEM_OF_UNDYING_MAKE_SOUND:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.CONSUME_TOTEM);
|
entityEventPacket.setType(EntityEventType.CONSUME_TOTEM);
|
||||||
break;
|
break;
|
||||||
case SHEEP_GRAZE_OR_TNT_CART_EXPLODE:
|
case SHEEP_GRAZE_OR_TNT_CART_EXPLODE:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.MINECART_TNT_PRIME_FUSE);
|
entityEventPacket.setType(EntityEventType.MINECART_TNT_PRIME_FUSE);
|
||||||
break;
|
break;
|
||||||
case IRON_GOLEM_HOLD_POPPY:
|
case IRON_GOLEM_HOLD_POPPY:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.IRON_GOLEM_OFFER_FLOWER);
|
entityEventPacket.setType(EntityEventType.IRON_GOLEM_OFFER_FLOWER);
|
||||||
break;
|
break;
|
||||||
case IRON_GOLEM_EMPTY_HAND:
|
case IRON_GOLEM_EMPTY_HAND:
|
||||||
entityEventPacket.setEvent(EntityEventPacket.Event.IRON_GOLEM_WITHDRAW_FLOWER);
|
entityEventPacket.setType(EntityEventType.IRON_GOLEM_WITHDRAW_FLOWER);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
@ -42,18 +42,6 @@ public class JavaEntityTeleportTranslator extends PacketTranslator<ServerEntityT
|
|||||||
}
|
}
|
||||||
if (entity == null) return;
|
if (entity == null) return;
|
||||||
|
|
||||||
entity.moveAbsolute(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch());
|
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), packet.isOnGround());
|
||||||
|
|
||||||
if (entity.isMovePending()) {
|
|
||||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
|
||||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
moveEntityPacket.setPosition(entity.getPosition());
|
|
||||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
|
||||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
|
||||||
moveEntityPacket.setTeleported(true);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(moveEntityPacket);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,18 @@
|
|||||||
package org.geysermc.connector.network.translators.java.entity.player;
|
package org.geysermc.connector.network.translators.java.entity.player;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayerAbilitiesPacket> {
|
public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayerAbilitiesPacket> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,7 +46,7 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||||||
if (entity == null)
|
if (entity == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EntityDataDictionary metadata = entity.getMetadata();
|
EntityDataMap metadata = entity.getMetadata();
|
||||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
@ -50,24 +54,18 @@ public class JavaPlayerAbilitiesTranslator extends PacketTranslator<ServerPlayer
|
|||||||
entityDataPacket.getMetadata().putAll(metadata);
|
entityDataPacket.getMetadata().putAll(metadata);
|
||||||
session.getUpstream().sendPacket(entityDataPacket);
|
session.getUpstream().sendPacket(entityDataPacket);
|
||||||
|
|
||||||
int playerFlags = 0;
|
Set<AdventureSettingsPacket.Flag> playerFlags = new HashSet<>();
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
||||||
|
if (packet.isCanFly())
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
|
||||||
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
if (packet.isFlying())
|
||||||
playerFlags = setPlayerFlag(0x40, packet.isCanFly(), playerFlags); // can fly
|
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||||
playerFlags = setPlayerFlag(0x200, packet.isFlying(), playerFlags); // is flying
|
|
||||||
|
|
||||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
adventureSettingsPacket.setPlayerPermission(1);
|
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||||
session.getUpstream().sendPacket(adventureSettingsPacket);
|
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int setPlayerFlag(int flag, boolean value, int playerFlags) {
|
|
||||||
if (value) {
|
|
||||||
return playerFlags | flag;
|
|
||||||
} else {
|
|
||||||
return playerFlags & ~flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class JavaPlayerListEntryTranslator extends PacketTranslator<ServerPlayer
|
|||||||
if (packet.getAction() != PlayerListEntryAction.ADD_PLAYER && packet.getAction() != PlayerListEntryAction.REMOVE_PLAYER) return;
|
if (packet.getAction() != PlayerListEntryAction.ADD_PLAYER && packet.getAction() != PlayerListEntryAction.REMOVE_PLAYER) return;
|
||||||
|
|
||||||
PlayerListPacket translate = new PlayerListPacket();
|
PlayerListPacket translate = new PlayerListPacket();
|
||||||
translate.setType(packet.getAction() == PlayerListEntryAction.ADD_PLAYER ? PlayerListPacket.Type.ADD : PlayerListPacket.Type.REMOVE);
|
translate.setAction(packet.getAction() == PlayerListEntryAction.ADD_PLAYER ? PlayerListPacket.Action.ADD : PlayerListPacket.Action.REMOVE);
|
||||||
|
|
||||||
for (PlayerListEntry entry : packet.getEntries()) {
|
for (PlayerListEntry entry : packet.getEntries()) {
|
||||||
if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
|
if (packet.getAction() == PlayerListEntryAction.ADD_PLAYER) {
|
||||||
|
@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity.player;
|
|||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.EntityEventType;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
|
|
||||||
import org.geysermc.connector.console.GeyserLogger;
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.entity.type.EntityType;
|
import org.geysermc.connector.entity.type.EntityType;
|
||||||
@ -48,17 +50,18 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||||||
|
|
||||||
if (!session.isSpawned()) {
|
if (!session.isSpawned()) {
|
||||||
Vector3f pos = Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ());
|
Vector3f pos = Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ());
|
||||||
entity.moveAbsolute(pos, packet.getYaw(), packet.getPitch());
|
entity.setPosition(pos);
|
||||||
|
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
|
||||||
|
|
||||||
RespawnPacket respawnPacket = new RespawnPacket();
|
RespawnPacket respawnPacket = new RespawnPacket();
|
||||||
respawnPacket.setRuntimeEntityId(0);
|
respawnPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
respawnPacket.setPosition(pos);
|
respawnPacket.setPosition(pos);
|
||||||
respawnPacket.setSpawnState(RespawnPacket.State.SERVER_READY);
|
respawnPacket.setState(RespawnPacket.State.SERVER_READY);
|
||||||
session.getUpstream().sendPacket(respawnPacket);
|
session.getUpstream().sendPacket(respawnPacket);
|
||||||
|
|
||||||
EntityEventPacket eventPacket = new EntityEventPacket();
|
EntityEventPacket eventPacket = new EntityEventPacket();
|
||||||
eventPacket.setRuntimeEntityId(entity.getGeyserId());
|
eventPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||||
eventPacket.setEvent(EntityEventPacket.Event.RESPAWN);
|
eventPacket.setType(EntityEventType.RESPAWN);
|
||||||
eventPacket.setData(0);
|
eventPacket.setData(0);
|
||||||
session.getUpstream().sendPacket(eventPacket);
|
session.getUpstream().sendPacket(eventPacket);
|
||||||
|
|
||||||
@ -72,28 +75,28 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||||||
movePlayerPacket.setPosition(pos);
|
movePlayerPacket.setPosition(pos);
|
||||||
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
||||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||||
movePlayerPacket.setOnGround(true);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(movePlayerPacket);
|
session.getUpstream().sendPacket(movePlayerPacket);
|
||||||
session.setSpawned(true);
|
session.setSpawned(true);
|
||||||
|
|
||||||
|
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
|
||||||
|
session.getDownstream().getSession().send(teleportConfirmPacket);
|
||||||
|
|
||||||
GeyserLogger.DEFAULT.info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ());
|
GeyserLogger.DEFAULT.info("Spawned player at " + packet.getX() + " " + packet.getY() + " " + packet.getZ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity.moveAbsolute(Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()), packet.getYaw(), packet.getPitch());
|
|
||||||
|
|
||||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
|
||||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
|
||||||
movePlayerPacket.setPosition(Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.01f, packet.getZ()));
|
|
||||||
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
|
||||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
|
||||||
movePlayerPacket.setOnGround(true);
|
|
||||||
entity.setMovePending(false);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacket(movePlayerPacket);
|
|
||||||
session.setSpawned(true);
|
session.setSpawned(true);
|
||||||
|
if (!packet.getRelative().isEmpty()) {
|
||||||
|
entity.moveRelative(session, packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch(), true);
|
||||||
|
} else {
|
||||||
|
double xDis = Math.abs(entity.getPosition().getX() - packet.getX());
|
||||||
|
double yDis = entity.getPosition().getY() - packet.getY();
|
||||||
|
double zDis = Math.abs(entity.getPosition().getZ() - packet.getZ());
|
||||||
|
if (xDis > 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) {
|
||||||
|
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
|
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
|
||||||
session.getDownstream().getSession().send(teleportConfirmPacket);
|
session.getDownstream().getSession().send(teleportConfirmPacket);
|
||||||
|
@ -50,6 +50,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlaye
|
|||||||
entity.setEntityId(packet.getEntityId());
|
entity.setEntityId(packet.getEntityId());
|
||||||
entity.setPosition(position);
|
entity.setPosition(position);
|
||||||
entity.setRotation(rotation);
|
entity.setRotation(rotation);
|
||||||
|
session.getEntityCache().cacheEntity(entity);
|
||||||
|
|
||||||
// async skin loading
|
// async skin loading
|
||||||
if (session.getUpstream().isInitialized()) {
|
if (session.getUpstream().isInitialized()) {
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
|
|
||||||
package org.geysermc.connector.network.translators.java.world;
|
package org.geysermc.connector.network.translators.java.world;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
||||||
import com.nukkitx.math.vector.Vector2i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
|
||||||
import com.nukkitx.network.VarInts;
|
import com.nukkitx.network.VarInts;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.geysermc.api.Geyser;
|
import org.geysermc.api.Geyser;
|
||||||
@ -46,51 +46,61 @@ public class JavaChunkDataTranslator extends PacketTranslator<ServerChunkDataPac
|
|||||||
public void translate(ServerChunkDataPacket packet, GeyserSession session) {
|
public void translate(ServerChunkDataPacket packet, GeyserSession session) {
|
||||||
// Not sure if this is safe or not, however without this the client usually times out
|
// Not sure if this is safe or not, however without this the client usually times out
|
||||||
Geyser.getConnector().getGeneralThreadPool().execute(() -> {
|
Geyser.getConnector().getGeneralThreadPool().execute(() -> {
|
||||||
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(session.getRenderDistance() << 4);
|
|
||||||
session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
|
|
||||||
|
|
||||||
session.setLastChunkPosition(newChunkPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn());
|
if (packet.getColumn().getBiomeData() != null) { //Full chunk
|
||||||
ByteBuf byteBuf = Unpooled.buffer(32);
|
ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn());
|
||||||
ChunkSection[] sections = chunkData.sections;
|
ByteBuf byteBuf = Unpooled.buffer(32);
|
||||||
|
ChunkSection[] sections = chunkData.sections;
|
||||||
|
|
||||||
int sectionCount = sections.length - 1;
|
int sectionCount = sections.length - 1;
|
||||||
while (sectionCount >= 0 && sections[sectionCount].isEmpty()) {
|
while (sectionCount >= 0 && sections[sectionCount].isEmpty()) {
|
||||||
sectionCount--;
|
sectionCount--;
|
||||||
|
}
|
||||||
|
sectionCount++;
|
||||||
|
|
||||||
|
for (int i = 0; i < sectionCount; i++) {
|
||||||
|
ChunkSection section = chunkData.sections[i];
|
||||||
|
section.writeToNetwork(byteBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bedrockBiome = BiomeTranslator.toBedrockBiome(packet.getColumn().getBiomeData());
|
||||||
|
|
||||||
|
byteBuf.writeBytes(bedrockBiome); // Biomes - 256 bytes
|
||||||
|
byteBuf.writeByte(0); // Border blocks - Edu edition only
|
||||||
|
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
||||||
|
|
||||||
|
byte[] payload = new byte[byteBuf.writerIndex()];
|
||||||
|
byteBuf.readBytes(payload);
|
||||||
|
|
||||||
|
LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
|
||||||
|
levelChunkPacket.setSubChunksLength(sectionCount);
|
||||||
|
levelChunkPacket.setCachingEnabled(false);
|
||||||
|
levelChunkPacket.setChunkX(packet.getColumn().getX());
|
||||||
|
levelChunkPacket.setChunkZ(packet.getColumn().getZ());
|
||||||
|
levelChunkPacket.setData(payload);
|
||||||
|
session.getUpstream().sendPacket(levelChunkPacket);
|
||||||
|
} else {
|
||||||
|
final int xOffset = packet.getColumn().getX() << 4;
|
||||||
|
final int zOffset = packet.getColumn().getZ() << 4;
|
||||||
|
Chunk[] chunks = packet.getColumn().getChunks();
|
||||||
|
for (int i = 0; i < chunks.length; i++) {
|
||||||
|
Chunk chunk = chunks[i];
|
||||||
|
if (chunk == null) continue;
|
||||||
|
final int yOffset = i * 16;
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
BlockState blockState = chunk.get(x, y, z);
|
||||||
|
Vector3i pos = Vector3i.from(
|
||||||
|
x + xOffset,
|
||||||
|
y + yOffset,
|
||||||
|
z + zOffset);
|
||||||
|
ChunkUtils.updateBlock(session, blockState, pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sectionCount++;
|
|
||||||
|
|
||||||
for (int i = 0; i < sectionCount; i++) {
|
|
||||||
ChunkSection section = chunkData.sections[i];
|
|
||||||
section.writeToNetwork(byteBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bedrockBiome = BiomeTranslator.toBedrockBiome(packet.getColumn().getBiomeData());
|
|
||||||
|
|
||||||
byteBuf.writeBytes(bedrockBiome); // Biomes - 256 bytes
|
|
||||||
byteBuf.writeByte(0); // Border blocks - Edu edition only
|
|
||||||
VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now
|
|
||||||
|
|
||||||
byte[] payload = new byte[byteBuf.writerIndex()];
|
|
||||||
byteBuf.readBytes(payload);
|
|
||||||
|
|
||||||
LevelChunkPacket levelChunkPacket = new LevelChunkPacket();
|
|
||||||
levelChunkPacket.setSubChunksLength(sectionCount);
|
|
||||||
levelChunkPacket.setCachingEnabled(false);
|
|
||||||
levelChunkPacket.setChunkX(packet.getColumn().getX());
|
|
||||||
levelChunkPacket.setChunkZ(packet.getColumn().getZ());
|
|
||||||
levelChunkPacket.setData(payload);
|
|
||||||
session.getUpstream().sendPacket(levelChunkPacket);
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,17 @@ import com.github.steveice10.mc.protocol.data.game.world.notify.EnterCreditsValu
|
|||||||
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||||
import com.nukkitx.math.vector.Vector3f;
|
import com.nukkitx.math.vector.Vector3f;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityDataDictionary;
|
import com.nukkitx.protocol.bedrock.data.EntityDataMap;
|
||||||
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
import com.nukkitx.protocol.bedrock.data.EntityFlag;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
||||||
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import org.geysermc.connector.entity.Entity;
|
import org.geysermc.connector.entity.Entity;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyClientPacket> {
|
||||||
@ -51,27 +55,34 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
switch (packet.getNotification()) {
|
switch (packet.getNotification()) {
|
||||||
case START_RAIN:
|
case START_RAIN:
|
||||||
LevelEventPacket startRainPacket = new LevelEventPacket();
|
LevelEventPacket startRainPacket = new LevelEventPacket();
|
||||||
startRainPacket.setEvent(LevelEventPacket.Event.START_RAIN);
|
startRainPacket.setType(LevelEventType.START_RAIN);
|
||||||
startRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
startRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
||||||
startRainPacket.setPosition(Vector3f.ZERO);
|
startRainPacket.setPosition(Vector3f.ZERO);
|
||||||
session.getUpstream().sendPacket(startRainPacket);
|
session.getUpstream().sendPacket(startRainPacket);
|
||||||
break;
|
break;
|
||||||
case STOP_RAIN:
|
case STOP_RAIN:
|
||||||
LevelEventPacket stopRainPacket = new LevelEventPacket();
|
LevelEventPacket stopRainPacket = new LevelEventPacket();
|
||||||
stopRainPacket.setEvent(LevelEventPacket.Event.STOP_RAIN);
|
stopRainPacket.setType(LevelEventType.STOP_RAIN);
|
||||||
stopRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
stopRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
|
||||||
stopRainPacket.setPosition(Vector3f.ZERO);
|
stopRainPacket.setPosition(Vector3f.ZERO);
|
||||||
session.getUpstream().sendPacket(stopRainPacket);
|
session.getUpstream().sendPacket(stopRainPacket);
|
||||||
break;
|
break;
|
||||||
case CHANGE_GAMEMODE:
|
case CHANGE_GAMEMODE:
|
||||||
int playerFlags = 0;
|
Set<AdventureSettingsPacket.Flag> playerFlags = new HashSet<>();
|
||||||
|
|
||||||
GameMode gameMode = (GameMode) packet.getValue();
|
GameMode gameMode = (GameMode) packet.getValue();
|
||||||
playerFlags = setPlayerFlag(0x01, gameMode == GameMode.ADVENTURE, playerFlags); // world immutable
|
if (gameMode == GameMode.ADVENTURE)
|
||||||
playerFlags = setPlayerFlag(0x20, true, playerFlags); // auto jump
|
playerFlags.add(AdventureSettingsPacket.Flag.IMMUTABLE_WORLD);
|
||||||
playerFlags = setPlayerFlag(0x40, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR, playerFlags); // can fly
|
|
||||||
playerFlags = setPlayerFlag(0x80, gameMode == GameMode.SPECTATOR, playerFlags); // no clip
|
if (gameMode == GameMode.CREATIVE)
|
||||||
playerFlags = setPlayerFlag(0x200, gameMode == GameMode.SPECTATOR, playerFlags); // is flying
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
|
||||||
|
if (gameMode == GameMode.SPECTATOR) {
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.NO_CLIP);
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.FLYING);
|
||||||
|
}
|
||||||
|
|
||||||
|
playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
|
||||||
|
|
||||||
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
||||||
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
playerGameTypePacket.setGamemode(gameMode.ordinal());
|
||||||
@ -79,12 +90,12 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
session.setGameMode(gameMode);
|
session.setGameMode(gameMode);
|
||||||
|
|
||||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||||
adventureSettingsPacket.setPlayerPermission(1);
|
adventureSettingsPacket.setPlayerPermission(PlayerPermission.OPERATOR);
|
||||||
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
|
||||||
adventureSettingsPacket.setPlayerFlags(playerFlags);
|
adventureSettingsPacket.getFlags().addAll(playerFlags);
|
||||||
session.getUpstream().sendPacket(adventureSettingsPacket);
|
session.getUpstream().sendPacket(adventureSettingsPacket);
|
||||||
|
|
||||||
EntityDataDictionary metadata = entity.getMetadata();
|
EntityDataMap metadata = entity.getMetadata();
|
||||||
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR);
|
metadata.getFlags().setFlag(EntityFlag.CAN_FLY, gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR);
|
||||||
|
|
||||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||||
@ -110,12 +121,4 @@ public class JavaNotifyClientTranslator extends PacketTranslator<ServerNotifyCli
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int setPlayerFlag(int flag, boolean value, int playerFlags) {
|
|
||||||
if (value) {
|
|
||||||
return playerFlags | flag;
|
|
||||||
} else {
|
|
||||||
return playerFlags & ~flag;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewDistancePacket;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
public class JavaUpdateViewDistanceTranslator extends PacketTranslator<ServerUpdateViewDistancePacket> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void translate(ServerUpdateViewDistancePacket packet, GeyserSession session) {
|
||||||
|
session.setRenderDistance(packet.getViewDistance());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.world;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket;
|
||||||
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
|
||||||
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
|
|
||||||
|
public class JavaUpdateViewPositionTranslator extends PacketTranslator<ServerUpdateViewPositionPacket> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void translate(ServerUpdateViewPositionPacket packet, GeyserSession session) {
|
||||||
|
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket();
|
||||||
|
chunkPublisherUpdatePacket.setPosition(Vector3i.from(packet.getChunkX() << 4, 0, packet.getChunkZ() << 4));
|
||||||
|
chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4);
|
||||||
|
session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
|
||||||
|
}
|
||||||
|
}
|
@ -31,7 +31,6 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
|||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
|
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.TranslatorsInit;
|
import org.geysermc.connector.network.translators.TranslatorsInit;
|
||||||
@ -76,19 +75,23 @@ public class ChunkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
|
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
|
||||||
int blockId = BlockTranslator.getBedrockBlockId(blockState);
|
|
||||||
Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
|
Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
|
||||||
|
updateBlock(session, blockState, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateBlock(GeyserSession session, BlockState blockState, Vector3i position) {
|
||||||
|
int blockId = BlockTranslator.getBedrockBlockId(blockState);
|
||||||
|
|
||||||
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
||||||
updateBlockPacket.setDataLayer(0);
|
updateBlockPacket.setDataLayer(0);
|
||||||
updateBlockPacket.setBlockPosition(pos);
|
updateBlockPacket.setBlockPosition(position);
|
||||||
updateBlockPacket.setRuntimeId(blockId);
|
updateBlockPacket.setRuntimeId(blockId);
|
||||||
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
|
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
|
||||||
session.getUpstream().sendPacket(updateBlockPacket);
|
session.getUpstream().sendPacket(updateBlockPacket);
|
||||||
|
|
||||||
UpdateBlockPacket waterPacket = new UpdateBlockPacket();
|
UpdateBlockPacket waterPacket = new UpdateBlockPacket();
|
||||||
waterPacket.setDataLayer(1);
|
waterPacket.setDataLayer(1);
|
||||||
waterPacket.setBlockPosition(pos);
|
waterPacket.setBlockPosition(position);
|
||||||
if (BlockTranslator.isWaterlogged(blockState)) {
|
if (BlockTranslator.isWaterlogged(blockState)) {
|
||||||
waterPacket.setRuntimeId(BEDROCK_WATER_ID);
|
waterPacket.setRuntimeId(BEDROCK_WATER_ID);
|
||||||
} else {
|
} else {
|
||||||
@ -100,11 +103,6 @@ public class ChunkUtils {
|
|||||||
public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) {
|
public static void sendEmptyChunks(GeyserSession session, Vector3i position, int radius, boolean forceUpdate) {
|
||||||
int chunkX = position.getX() >> 4;
|
int chunkX = position.getX() >> 4;
|
||||||
int chunkZ = position.getZ() >> 4;
|
int chunkZ = position.getZ() >> 4;
|
||||||
NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket();
|
|
||||||
chunkPublisherUpdatePacket.setPosition(position);
|
|
||||||
chunkPublisherUpdatePacket.setRadius(radius + 1 << 4);
|
|
||||||
session.getUpstream().sendPacket(chunkPublisherUpdatePacket);
|
|
||||||
session.setLastChunkPosition(null);
|
|
||||||
for (int x = -radius; x <= radius; x++) {
|
for (int x = -radius; x <= radius; x++) {
|
||||||
for (int z = -radius; z <= radius; z++) {
|
for (int z = -radius; z <= radius; z++) {
|
||||||
LevelChunkPacket data = new LevelChunkPacket();
|
LevelChunkPacket data = new LevelChunkPacket();
|
||||||
@ -119,7 +117,7 @@ public class ChunkUtils {
|
|||||||
Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4);
|
Vector3i pos = Vector3i.from(chunkX + x << 4, 80, chunkZ + z << 4);
|
||||||
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
|
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
|
||||||
blockPacket.setBlockPosition(pos);
|
blockPacket.setBlockPosition(pos);
|
||||||
blockPacket.setDataLayer(1);
|
blockPacket.setDataLayer(0);
|
||||||
blockPacket.setRuntimeId(1);
|
blockPacket.setRuntimeId(1);
|
||||||
session.getUpstream().sendPacket(blockPacket);
|
session.getUpstream().sendPacket(blockPacket);
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,18 @@ import org.geysermc.connector.entity.Entity;
|
|||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
|
|
||||||
public class DimensionUtils {
|
public class DimensionUtils {
|
||||||
public static void switchDimension(GeyserSession session, int javaDimension, boolean fake) {
|
public static void switchDimension(GeyserSession session, int javaDimension) {
|
||||||
int bedrockDimension = javaToBedrock(javaDimension);
|
int bedrockDimension = javaToBedrock(javaDimension);
|
||||||
Entity player = session.getPlayerEntity();
|
Entity player = session.getPlayerEntity();
|
||||||
if (bedrockDimension == player.getDimension())
|
if (bedrockDimension == player.getDimension())
|
||||||
return;
|
return;
|
||||||
Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);
|
|
||||||
|
|
||||||
session.getEntityCache().removeAllEntities();
|
session.getEntityCache().removeAllEntities();
|
||||||
|
if (session.getPendingDimSwitches().getAndIncrement() > 0) {
|
||||||
|
ChunkUtils.sendEmptyChunks(session, player.getPosition().toInt(), 3, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3i pos = Vector3i.from(0, Short.MAX_VALUE, 0);
|
||||||
|
|
||||||
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
|
ChangeDimensionPacket changeDimensionPacket = new ChangeDimensionPacket();
|
||||||
changeDimensionPacket.setDimension(bedrockDimension);
|
changeDimensionPacket.setDimension(bedrockDimension);
|
||||||
@ -46,19 +50,14 @@ public class DimensionUtils {
|
|||||||
changeDimensionPacket.setPosition(pos.toFloat());
|
changeDimensionPacket.setPosition(pos.toFloat());
|
||||||
session.getUpstream().sendPacket(changeDimensionPacket);
|
session.getUpstream().sendPacket(changeDimensionPacket);
|
||||||
player.setDimension(bedrockDimension);
|
player.setDimension(bedrockDimension);
|
||||||
|
player.setPosition(pos.toFloat());
|
||||||
|
session.setSpawned(false);
|
||||||
|
|
||||||
//let java server handle portal travel sound
|
//let java server handle portal travel sound
|
||||||
StopSoundPacket stopSoundPacket = new StopSoundPacket();
|
StopSoundPacket stopSoundPacket = new StopSoundPacket();
|
||||||
stopSoundPacket.setStoppingAllSound(true);
|
stopSoundPacket.setStoppingAllSound(true);
|
||||||
stopSoundPacket.setSoundName("");
|
stopSoundPacket.setSoundName("");
|
||||||
session.getUpstream().sendPacket(stopSoundPacket);
|
session.getUpstream().sendPacket(stopSoundPacket);
|
||||||
|
|
||||||
if (fake) {
|
|
||||||
ChunkUtils.sendEmptyChunks(session, pos, 2, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
session.setSpawned(false);
|
|
||||||
session.setSwitchingDimension(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int javaToBedrock(int javaDimension) {
|
public static int javaToBedrock(int javaDimension) {
|
||||||
|
@ -165,12 +165,12 @@ public class SkinUtils {
|
|||||||
);
|
);
|
||||||
|
|
||||||
PlayerListPacket playerRemovePacket = new PlayerListPacket();
|
PlayerListPacket playerRemovePacket = new PlayerListPacket();
|
||||||
playerRemovePacket.setType(PlayerListPacket.Type.REMOVE);
|
playerRemovePacket.setAction(PlayerListPacket.Action.REMOVE);
|
||||||
playerRemovePacket.getEntries().add(updatedEntry);
|
playerRemovePacket.getEntries().add(updatedEntry);
|
||||||
session.getUpstream().sendPacket(playerRemovePacket);
|
session.getUpstream().sendPacket(playerRemovePacket);
|
||||||
|
|
||||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||||
playerAddPacket.setType(PlayerListPacket.Type.ADD);
|
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||||
playerAddPacket.getEntries().add(updatedEntry);
|
playerAddPacket.getEntries().add(updatedEntry);
|
||||||
session.getUpstream().sendPacket(playerAddPacket);
|
session.getUpstream().sendPacket(playerAddPacket);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ package org.geysermc.connector.world.chunk;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@ -35,6 +36,7 @@ import java.util.Objects;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
public class ChunkPosition {
|
public class ChunkPosition {
|
||||||
|
|
||||||
private int x;
|
private int x;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren