Fix entity dismounting, and fix Java player death animations.
This commit is contained in:
1 parent
e03ec619c1
commit
4094fab5d2
2 files changed
+125
-22
No files matched your search
@@ -57,13 +57,19 @@ function connectToJavaServer(proxy, client) {
|
||||
if (client.state === "play") {
|
||||
let reason = 10;
|
||||
if (packet.reason) {
|
||||
const reasonText = typeof packet.reason === "string" ? packet.reason : JSON.stringify(packet.reason);
|
||||
const reasonText =
|
||||
typeof packet.reason === "string"
|
||||
? packet.reason
|
||||
: JSON.stringify(packet.reason);
|
||||
const lowerReason = reasonText.toLowerCase();
|
||||
if (lowerReason.includes("ban")) {
|
||||
reason = 10;
|
||||
} else if (lowerReason.includes("kick")) {
|
||||
reason = 10;
|
||||
} else if (lowerReason.includes("timeout") || lowerReason.includes("timed out")) {
|
||||
} else if (
|
||||
lowerReason.includes("timeout") ||
|
||||
lowerReason.includes("timed out")
|
||||
) {
|
||||
reason = 20;
|
||||
} else if (lowerReason.includes("full")) {
|
||||
reason = 23;
|
||||
@@ -507,12 +513,33 @@ function connectToJavaServer(proxy, client) {
|
||||
if (uuid && client.javaPlayers.has(uuid)) {
|
||||
const player = client.javaPlayers.get(uuid);
|
||||
if (player.spawned && player.entityId) {
|
||||
const removeWriter = new PacketWriter();
|
||||
removeWriter.writeByte(1);
|
||||
removeWriter.writeInt(player.entityId);
|
||||
proxy.sendPacket(client, 0x1d, removeWriter.toBuffer());
|
||||
const isDying =
|
||||
client._dyingPlayers &&
|
||||
client._dyingPlayers.has(player.javaEntityId);
|
||||
|
||||
if (!isDying) {
|
||||
const removeWriter = new PacketWriter();
|
||||
removeWriter.writeByte(1);
|
||||
removeWriter.writeInt(player.entityId);
|
||||
proxy.sendPacket(client, 0x1d, removeWriter.toBuffer());
|
||||
client.javaPlayers.delete(uuid);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
if (client.javaPlayers.has(uuid)) {
|
||||
const removeWriter = new PacketWriter();
|
||||
removeWriter.writeByte(1);
|
||||
removeWriter.writeInt(player.entityId);
|
||||
proxy.sendPacket(client, 0x1d, removeWriter.toBuffer());
|
||||
client.javaPlayers.delete(uuid);
|
||||
}
|
||||
if (client._dyingPlayers) {
|
||||
client._dyingPlayers.delete(player.javaEntityId);
|
||||
}
|
||||
}, 1500);
|
||||
}
|
||||
} else {
|
||||
client.javaPlayers.delete(uuid);
|
||||
}
|
||||
client.javaPlayers.delete(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,11 +575,35 @@ function connectToJavaServer(proxy, client) {
|
||||
if (playerName !== "Player") {
|
||||
playerInfo.name = playerName;
|
||||
}
|
||||
if (playerInfo.javaEntityId && client._dyingPlayers) {
|
||||
client._dyingPlayers.delete(playerInfo.javaEntityId);
|
||||
}
|
||||
}
|
||||
|
||||
const lceEntityId = proxy.mapJavaEntityIdToLce(client, packet.entityId);
|
||||
if (
|
||||
playerInfo.javaEntityId &&
|
||||
playerInfo.javaEntityId !== packet.entityId
|
||||
) {
|
||||
if (client.javaToLceEntityId.has(playerInfo.javaEntityId)) {
|
||||
const oldLceId = client.javaToLceEntityId.get(
|
||||
playerInfo.javaEntityId,
|
||||
);
|
||||
client.javaToLceEntityId.delete(playerInfo.javaEntityId);
|
||||
client.javaToLceEntityId.set(packet.entityId, oldLceId);
|
||||
playerInfo.entityId = oldLceId;
|
||||
} else {
|
||||
playerInfo.entityId = proxy.mapJavaEntityIdToLce(
|
||||
client,
|
||||
packet.entityId,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
playerInfo.entityId = proxy.mapJavaEntityIdToLce(
|
||||
client,
|
||||
packet.entityId,
|
||||
);
|
||||
}
|
||||
|
||||
playerInfo.entityId = lceEntityId;
|
||||
playerInfo.javaEntityId = packet.entityId;
|
||||
playerInfo.x = packet.x / 32;
|
||||
playerInfo.y = packet.y / 32;
|
||||
@@ -561,6 +612,13 @@ function connectToJavaServer(proxy, client) {
|
||||
playerInfo.pitch = (packet.pitch / 256) * 360;
|
||||
|
||||
if (playerInfo.name && playerInfo.name !== "Player") {
|
||||
if (playerInfo.spawned) {
|
||||
const removeWriter = new PacketWriter();
|
||||
removeWriter.writeByte(1);
|
||||
removeWriter.writeInt(playerInfo.entityId);
|
||||
proxy.sendPacket(client, 0x1d, removeWriter.toBuffer());
|
||||
}
|
||||
|
||||
playerInfo.spawned = true;
|
||||
try {
|
||||
proxy.sendAddPlayerPacket(client, playerInfo);
|
||||
@@ -1627,6 +1685,8 @@ function connectToJavaServer(proxy, client) {
|
||||
|
||||
if (riderJavaId === client.javaPlayerEntityId) {
|
||||
riderId = client.lcePlayerEntityId || client.smallId;
|
||||
client.isRiding = vehicleJavaId !== -1;
|
||||
client.ridingEntityId = vehicleJavaId;
|
||||
} else {
|
||||
for (const [uuid, player] of client.javaPlayers) {
|
||||
if (player.javaEntityId === riderJavaId && player.spawned) {
|
||||
|
||||
+56
-13
@@ -355,6 +355,9 @@ class LCEProxy {
|
||||
case 0x13:
|
||||
return 1 + 9;
|
||||
|
||||
case 0x1b:
|
||||
return 1 + 10;
|
||||
|
||||
case 0x66:
|
||||
let containerClickSize = 1 + 1 + 2 + 1 + 2 + 1;
|
||||
if (offset + containerClickSize + 2 <= data.length) {
|
||||
@@ -487,6 +490,11 @@ class LCEProxy {
|
||||
this.handlePlayerCommand(client, packetData);
|
||||
}
|
||||
break;
|
||||
case 0x1b: //PlayerInputPacket - 27
|
||||
if (client.state === "play") {
|
||||
this.handlePlayerInput(client, packetData);
|
||||
}
|
||||
break;
|
||||
case 0x65: //ContainerClosePacket - 101
|
||||
if (client.state === "play") {
|
||||
this.handleContainerClose(client, packetData);
|
||||
@@ -1818,24 +1826,20 @@ class LCEProxy {
|
||||
const action = reader.readByte();
|
||||
const actionData = reader.readInt();
|
||||
|
||||
const actionNames = {
|
||||
1: "START_SNEAKING",
|
||||
2: "STOP_SNEAKING",
|
||||
3: "STOP_SLEEPING",
|
||||
4: "START_SPRINTING",
|
||||
5: "STOP_SPRINTING",
|
||||
6: "START_IDLEANIM",
|
||||
7: "STOP_IDLEANIM",
|
||||
8: "RIDING_JUMP",
|
||||
9: "OPEN_INVENTORY",
|
||||
};
|
||||
|
||||
if (client.javaClient && client.javaClient.write) {
|
||||
try {
|
||||
let javaAction = -1;
|
||||
|
||||
if (action === 1) {
|
||||
javaAction = 0; //java: START_SNEAKING
|
||||
javaAction = 0;
|
||||
if (client.isRiding) {
|
||||
client.javaClient.write("steer_vehicle", {
|
||||
sideways: 0,
|
||||
forward: 0,
|
||||
jump: false,
|
||||
unmount: true,
|
||||
});
|
||||
}
|
||||
} else if (action === 2) {
|
||||
javaAction = 1; //java: STOP_SNEAKING
|
||||
} else if (action === 3) {
|
||||
@@ -1863,6 +1867,45 @@ class LCEProxy {
|
||||
}
|
||||
}
|
||||
|
||||
handlePlayerInput(client, data) {
|
||||
const reader = new PacketReader(data.slice(1));
|
||||
const xxa = reader.readFloat();
|
||||
const yya = reader.readFloat();
|
||||
const isJumping = reader.readBoolean();
|
||||
const isSneaking = reader.readBoolean();
|
||||
|
||||
if (client.javaClient && client.javaClient.write) {
|
||||
try {
|
||||
if (client.isRiding) {
|
||||
if (isSneaking && !client.sentSneak) {
|
||||
client.sentSneak = true;
|
||||
client.javaClient.write("entity_action", {
|
||||
entityId: client.javaPlayerEntityId,
|
||||
actionId: 0,
|
||||
jumpBoost: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSneaking) {
|
||||
client.sentSneak = false;
|
||||
}
|
||||
|
||||
if (xxa !== 0 || yya !== 0 || isJumping) {
|
||||
client.javaClient.write("steer_vehicle", {
|
||||
sideways: xxa,
|
||||
forward: yya,
|
||||
jump: isJumping,
|
||||
unmount: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleContainerClose(client, data) {
|
||||
const reader = new PacketReader(data.slice(1));
|
||||
const containerId = reader.readByte();
|
||||
|
||||
Reference in new issue
Block a user