Added rabbits, door types, enchantments, multiserver support, written books, crafting, enchantments, NPC support, fixed death animations.
This commit is contained in:
1 parent
460470d458
commit
f506c2573a
15 files changed
+2804
-175
No files matched your search
@@ -180,7 +180,7 @@
|
||||
|
||||
# UI
|
||||
|
||||
- [ ] Crafting _(Hard to implement, coming soon)_
|
||||
- [x] Crafting
|
||||
- [x] Brewing stand
|
||||
- [x] Furnace
|
||||
- [x] Villager trading
|
||||
|
||||
+15
-9
@@ -1,21 +1,27 @@
|
||||
/* --------------------------------------------------------------- */
|
||||
/* constants.js */
|
||||
/* --------------------------------------------------------------- */
|
||||
const USE_LEGACY_USERNAME = false;
|
||||
const CUSTOM_USERNAME = "LCE_Player";
|
||||
|
||||
const SERVERS = [
|
||||
{ server: "us-1.creepernation.net:25568", cracked: true },
|
||||
{ server: "hypixel.net", cracked: false },
|
||||
{ server: "localhost:25564", cracked: true },
|
||||
];
|
||||
|
||||
/* DONT TOUCH THESE BELOW THINGS UNLESS YOU KNOW WHAT YOURE DOING! */
|
||||
|
||||
const GAME_PORT = 25565;
|
||||
const WIN64_LAN_DISCOVERY_PORT = 25566;
|
||||
const MINECRAFT_NET_VERSION = 560;
|
||||
const JAVA_SERVER_HOST = "localhost"; // The java edition server host that the proxy will connect to.
|
||||
const JAVA_SERVER_PORT = 25564; // The java edition server port that the proxy will connect to.
|
||||
const PROXY_NAME = JAVA_SERVER_HOST + ":" + JAVA_SERVER_PORT;
|
||||
|
||||
module.exports = {
|
||||
GAME_PORT,
|
||||
WIN64_LAN_DISCOVERY_PORT,
|
||||
MINECRAFT_NET_VERSION,
|
||||
USE_JAVA_ACCOUNT: false, // Allows use of a microsoft java account for online servers. (Disable this if you don't own java - you'll only be able to connect to cracked/offline servers.)
|
||||
USE_LEGACY_USERNAME: false, // You can use your legacy edition username, or a custom username below. (offline servers only)
|
||||
CUSTOM_USERNAME: "LCE_Player", // The custom username used if USE_LEGACY_USERNAME is false. Ensure it's UNDER 16 characters. (offline servers only)
|
||||
JAVA_SERVER_HOST,
|
||||
JAVA_SERVER_PORT,
|
||||
PROXY_NAME,
|
||||
USE_LEGACY_USERNAME,
|
||||
CUSTOM_USERNAME,
|
||||
SERVERS,
|
||||
};
|
||||
/* --------------------------------------------------------------- */
|
||||
+385
-44
@@ -1,11 +1,11 @@
|
||||
/* --------------------------------------------------------------- */
|
||||
/* javaclienthandler.js */
|
||||
/* --------------------------------------------------------------- */
|
||||
|
||||
//beware that there are a lot of magic numbers, need to do a refractor soon.
|
||||
|
||||
const mc = require("minecraft-protocol");
|
||||
const {
|
||||
JAVA_SERVER_HOST,
|
||||
JAVA_SERVER_PORT,
|
||||
USE_JAVA_ACCOUNT,
|
||||
USE_LEGACY_USERNAME,
|
||||
CUSTOM_USERNAME,
|
||||
} = require("../constants");
|
||||
@@ -15,13 +15,20 @@ const { mapJavaItemToLCE, mapJavaBlockToLCE } = require("./mappings");
|
||||
const { mapJavaSoundToLCE } = require("./mappings/soundmapping");
|
||||
const { parseChatComponent, stripColorCodes } = require("./utils/chat");
|
||||
const { countSetBits, compressRLE } = require("./utils/chunk");
|
||||
const { downloadSkin, generateCustomSkinName } = require("./utils/skins");
|
||||
const {
|
||||
downloadSkin,
|
||||
downloadCape,
|
||||
generateCustomSkinName,
|
||||
generateCustomCapeName,
|
||||
} = require("./utils/skins");
|
||||
const zlib = require("zlib");
|
||||
|
||||
async function connectToJavaServer(proxy, client) {
|
||||
const serverConfig = client.serverConfig;
|
||||
|
||||
let authConfig = {
|
||||
host: JAVA_SERVER_HOST,
|
||||
port: JAVA_SERVER_PORT,
|
||||
host: serverConfig.host,
|
||||
port: serverConfig.port,
|
||||
username: !USE_LEGACY_USERNAME
|
||||
? CUSTOM_USERNAME
|
||||
: client.username || "undefined",
|
||||
@@ -29,11 +36,11 @@ async function connectToJavaServer(proxy, client) {
|
||||
version: "1.8.9",
|
||||
};
|
||||
|
||||
if (USE_JAVA_ACCOUNT) {
|
||||
if (!serverConfig.cracked) {
|
||||
if (msAuth.isAuthenticated()) {
|
||||
authConfig = {
|
||||
host: JAVA_SERVER_HOST,
|
||||
port: JAVA_SERVER_PORT,
|
||||
host: serverConfig.host,
|
||||
port: serverConfig.port,
|
||||
username: msAuth.username,
|
||||
session: {
|
||||
accessToken: msAuth.accessToken,
|
||||
@@ -46,7 +53,22 @@ async function connectToJavaServer(proxy, client) {
|
||||
version: "1.8.9",
|
||||
};
|
||||
} else {
|
||||
console.error("Not authenticated! This should not happen.");
|
||||
console.log(`Server ${serverConfig.name} requires authentication. Authenticating...`);
|
||||
await msAuth.authenticate();
|
||||
authConfig = {
|
||||
host: serverConfig.host,
|
||||
port: serverConfig.port,
|
||||
username: msAuth.username,
|
||||
session: {
|
||||
accessToken: msAuth.accessToken,
|
||||
selectedProfile: {
|
||||
id: msAuth.uuid,
|
||||
name: msAuth.username,
|
||||
},
|
||||
},
|
||||
auth: "microsoft",
|
||||
version: "1.8.9",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,6 +271,19 @@ async function connectToJavaServer(proxy, client) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.windowId >= 0) {
|
||||
if (!client._windowInventories) {
|
||||
client._windowInventories = {};
|
||||
}
|
||||
if (!client._windowInventories[packet.windowId]) {
|
||||
client._windowInventories[packet.windowId] = {};
|
||||
}
|
||||
|
||||
for (let i = 0; i < packet.items.length; i++) {
|
||||
client._windowInventories[packet.windowId][i] = packet.items[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (packet.windowId === 0) {
|
||||
if (!client.inventory) client.inventory = {};
|
||||
for (let i = 0; i < packet.items.length; i++) {
|
||||
@@ -276,7 +311,42 @@ async function connectToJavaServer(proxy, client) {
|
||||
|
||||
for (let i = 0; i < packet.items.length; i++) {
|
||||
try {
|
||||
proxy.writeItem(invWriter, packet.items[i]);
|
||||
const item = packet.items[i];
|
||||
|
||||
if (item && item.nbtData) {
|
||||
let displayName = null;
|
||||
let isEnchanted = false;
|
||||
try {
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
item.nbtData.value.display &&
|
||||
item.nbtData.value.display.value
|
||||
) {
|
||||
if (item.nbtData.value.display.value.Name) {
|
||||
displayName = item.nbtData.value.display.value.Name.value;
|
||||
}
|
||||
}
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
(item.nbtData.value.ench ||
|
||||
item.nbtData.value.Enchantments ||
|
||||
item.nbtData.value.StoredEnchantments)
|
||||
) {
|
||||
isEnchanted = true;
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
if (displayName) {
|
||||
item.displayName = displayName.replace(/§[0-9a-fk-or]/gi, "");
|
||||
}
|
||||
if (isEnchanted) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
proxy.writeItem(invWriter, item);
|
||||
} catch (err) {
|
||||
invWriter.writeShort(-1);
|
||||
}
|
||||
@@ -376,7 +446,42 @@ async function connectToJavaServer(proxy, client) {
|
||||
const slotWriter = new PacketWriter();
|
||||
slotWriter.writeByte(packet.windowId);
|
||||
slotWriter.writeShort(packet.slot);
|
||||
proxy.writeItem(slotWriter, packet.item);
|
||||
|
||||
const item = packet.item;
|
||||
if (item && item.nbtData) {
|
||||
let displayName = null;
|
||||
let isEnchanted = false;
|
||||
try {
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
item.nbtData.value.display &&
|
||||
item.nbtData.value.display.value
|
||||
) {
|
||||
if (item.nbtData.value.display.value.Name) {
|
||||
displayName = item.nbtData.value.display.value.Name.value;
|
||||
}
|
||||
}
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
(item.nbtData.value.ench ||
|
||||
item.nbtData.value.Enchantments ||
|
||||
item.nbtData.value.StoredEnchantments)
|
||||
) {
|
||||
isEnchanted = true;
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
if (displayName) {
|
||||
item.displayName = displayName;
|
||||
}
|
||||
if (isEnchanted) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
}
|
||||
|
||||
proxy.writeItem(slotWriter, item);
|
||||
|
||||
const payload = slotWriter.toBuffer();
|
||||
|
||||
@@ -524,13 +629,26 @@ async function connectToJavaServer(proxy, client) {
|
||||
for (const playerData of packet.data) {
|
||||
const uuid = playerData.UUID || playerData.uuid;
|
||||
if (uuid) {
|
||||
const existingPlayer = client.javaPlayers.get(uuid);
|
||||
const wasAlreadySpawned =
|
||||
existingPlayer && existingPlayer.spawned;
|
||||
let existingPlayer = client.javaPlayers.get(uuid);
|
||||
if (!existingPlayer) {
|
||||
existingPlayer = {
|
||||
name: playerData.name,
|
||||
addedToTablistTime: Date.now(),
|
||||
gamemode: 0,
|
||||
ping: 0,
|
||||
spawned: false,
|
||||
};
|
||||
client.javaPlayers.set(uuid, existingPlayer);
|
||||
} else {
|
||||
existingPlayer.addedToTablistTime = Date.now();
|
||||
}
|
||||
const wasAlreadySpawned = existingPlayer.spawned;
|
||||
|
||||
let skinId = 0;
|
||||
let skinUrl = null;
|
||||
let customTextureName = null;
|
||||
let capeUrl = null;
|
||||
let customCapeName = null;
|
||||
if (playerData.properties) {
|
||||
const texturesProp = playerData.properties.find(
|
||||
(p) => p.name === "textures",
|
||||
@@ -566,6 +684,37 @@ async function connectToJavaServer(proxy, client) {
|
||||
client,
|
||||
existingPlayerForSkin.entityId,
|
||||
customTextureName,
|
||||
0,
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
/* do nothing */
|
||||
});
|
||||
}
|
||||
if (parsed.textures && parsed.textures.CAPE) {
|
||||
capeUrl = parsed.textures.CAPE.url;
|
||||
customCapeName = generateCustomCapeName(playerData.name);
|
||||
|
||||
downloadCape(capeUrl)
|
||||
.then((capeData) => {
|
||||
proxy.sendTexturePacket(
|
||||
client,
|
||||
customCapeName,
|
||||
capeData,
|
||||
);
|
||||
|
||||
const existingPlayerForCape =
|
||||
client.javaPlayers.get(uuid);
|
||||
if (
|
||||
existingPlayerForCape &&
|
||||
existingPlayerForCape.entityId
|
||||
) {
|
||||
proxy.sendTextureChangePacket(
|
||||
client,
|
||||
existingPlayerForCape.entityId,
|
||||
customCapeName,
|
||||
1,
|
||||
);
|
||||
}
|
||||
})
|
||||
@@ -579,13 +728,17 @@ async function connectToJavaServer(proxy, client) {
|
||||
}
|
||||
}
|
||||
|
||||
const playerName = playerData.name || "Player";
|
||||
const isNPC = playerName.startsWith("[ZNPC]");
|
||||
const updatedPlayer = {
|
||||
name: playerData.name || "Player",
|
||||
name: playerName,
|
||||
gamemode: playerData.gamemode || 0,
|
||||
ping: playerData.ping || 0,
|
||||
skinId: skinId,
|
||||
skinUrl: skinUrl,
|
||||
customTextureName: customTextureName,
|
||||
capeUrl: capeUrl,
|
||||
customCapeName: customCapeName,
|
||||
entityId: existingPlayer ? existingPlayer.entityId : null,
|
||||
javaEntityId: existingPlayer
|
||||
? existingPlayer.javaEntityId
|
||||
@@ -600,6 +753,11 @@ async function connectToJavaServer(proxy, client) {
|
||||
? existingPlayer.readyToSpawn
|
||||
: false,
|
||||
needsSpawn: wasAlreadySpawned,
|
||||
addedViaPlayerInfo: true,
|
||||
isNPC: isNPC,
|
||||
addedToTablistTime: existingPlayer
|
||||
? existingPlayer.addedToTablistTime
|
||||
: Date.now(),
|
||||
};
|
||||
|
||||
client.javaPlayers.set(uuid, updatedPlayer);
|
||||
@@ -621,6 +779,10 @@ async function connectToJavaServer(proxy, client) {
|
||||
const uuid = playerData.UUID || playerData.uuid;
|
||||
if (uuid && client.javaPlayers.has(uuid)) {
|
||||
const player = client.javaPlayers.get(uuid);
|
||||
if (player.spawned) {
|
||||
player.isNPC = true;
|
||||
continue;
|
||||
}
|
||||
if (player.spawned && player.entityId) {
|
||||
const isDying =
|
||||
client._dyingPlayers &&
|
||||
@@ -672,12 +834,15 @@ async function connectToJavaServer(proxy, client) {
|
||||
}
|
||||
|
||||
if (!playerInfo) {
|
||||
const isNPC = playerName.startsWith("[ZNPC]");
|
||||
playerInfo = {
|
||||
name: playerName,
|
||||
gamemode: 0,
|
||||
ping: 0,
|
||||
entityId: packet.entityId,
|
||||
spawned: false,
|
||||
isNPC: isNPC,
|
||||
spawnTime: Date.now(),
|
||||
};
|
||||
client.javaPlayers.set(uuid, playerInfo);
|
||||
} else {
|
||||
@@ -731,6 +896,22 @@ async function connectToJavaServer(proxy, client) {
|
||||
playerInfo.spawned = true;
|
||||
try {
|
||||
proxy.sendAddPlayerPacket(client, playerInfo);
|
||||
if (playerInfo.customTextureName) {
|
||||
proxy.sendTextureChangePacket(
|
||||
client,
|
||||
playerInfo.entityId,
|
||||
playerInfo.customTextureName,
|
||||
0,
|
||||
);
|
||||
}
|
||||
if (playerInfo.customCapeName) {
|
||||
proxy.sendTextureChangePacket(
|
||||
client,
|
||||
playerInfo.entityId,
|
||||
playerInfo.customCapeName,
|
||||
1,
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
@@ -748,6 +929,7 @@ async function connectToJavaServer(proxy, client) {
|
||||
proxy.sendContainerOpenPacket(client, packet);
|
||||
client.openWindowId = packet.windowId;
|
||||
client.openWindowType = windowType;
|
||||
client._lastOpenTime = Date.now();
|
||||
|
||||
const isChest =
|
||||
windowType === "minecraft:chest" ||
|
||||
@@ -780,9 +962,29 @@ async function connectToJavaServer(proxy, client) {
|
||||
});
|
||||
|
||||
javaClient.on("custom_payload", (packet) => {
|
||||
if (client.state === "play" && packet.channel === "MC|TrList") {
|
||||
const windowId = client.openWindowId || 1;
|
||||
proxy.sendVillagerTrades(client, windowId, packet.data);
|
||||
if (client.state === "play") {
|
||||
if (packet.channel === "MC|TrList") {
|
||||
const windowId = client.openWindowId || 1;
|
||||
proxy.sendVillagerTrades(client, windowId, packet.data);
|
||||
} else if (packet.channel === "MC|BOpen") {
|
||||
let bookItem = null;
|
||||
if (client.inventory) {
|
||||
for (let i = 0; i < 45; i++) {
|
||||
const item = client.inventory[i];
|
||||
if (item && item.blockId === 387) {
|
||||
bookItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bookItem && (bookItem.nbt || bookItem.nbtData)) {
|
||||
if (!bookItem.nbt && bookItem.nbtData) {
|
||||
bookItem.nbt = bookItem.nbtData;
|
||||
}
|
||||
proxy.sendBookAsChestGUI(client, bookItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -860,6 +1062,9 @@ async function connectToJavaServer(proxy, client) {
|
||||
) {
|
||||
lceBlockId = 31;
|
||||
lceMetadata = 1;
|
||||
} else if (javaBlockId === 165) {
|
||||
lceBlockId = 95;
|
||||
lceMetadata = 5;
|
||||
}
|
||||
|
||||
if (lceBlockId < 0 || lceBlockId > 170) {
|
||||
@@ -1023,6 +1228,9 @@ async function connectToJavaServer(proxy, client) {
|
||||
) {
|
||||
lceBlockId = 31;
|
||||
lceMetadata = 1;
|
||||
} else if (javaBlockId === 165) {
|
||||
lceBlockId = 95;
|
||||
lceMetadata = 5;
|
||||
}
|
||||
|
||||
if (lceBlockId < 0 || lceBlockId > 170) {
|
||||
@@ -1073,12 +1281,6 @@ async function connectToJavaServer(proxy, client) {
|
||||
const javaType = proxy.getJavaEntityType(packet.type);
|
||||
const lceEntityType = proxy.javaEntityTypeMapping[javaType];
|
||||
|
||||
if (!lceEntityType) {
|
||||
}
|
||||
|
||||
if (lceEntityType < 0 || lceEntityType > 200) {
|
||||
}
|
||||
|
||||
const lceEntityId = proxy.mapJavaEntityIdToLce(client, packet.entityId);
|
||||
|
||||
const entityInfo = {
|
||||
@@ -1100,6 +1302,11 @@ async function connectToJavaServer(proxy, client) {
|
||||
metadata: packet.metadata || [],
|
||||
};
|
||||
|
||||
if (javaType === "Rabbit") {
|
||||
entityInfo.metadata.push({ key: 10, type: 4, value: "Rabbit" });
|
||||
entityInfo.metadata.push({ key: 11, type: 0, value: 1 });
|
||||
}
|
||||
|
||||
entityInfo.spawnTime = Date.now();
|
||||
|
||||
client.javaEntities.set(packet.entityId, entityInfo);
|
||||
@@ -1111,7 +1318,7 @@ async function connectToJavaServer(proxy, client) {
|
||||
}
|
||||
|
||||
const relevantMetadata = entityInfo.metadata.filter((m) => {
|
||||
return [12, 13, 16].includes(m.key) && m.type !== 5;
|
||||
return [10, 11, 12, 13, 16].includes(m.key) && m.type !== 5;
|
||||
});
|
||||
|
||||
if (relevantMetadata.length > 0) {
|
||||
@@ -1127,6 +1334,9 @@ async function connectToJavaServer(proxy, client) {
|
||||
javaClient.on("spawn_entity", (packet) => {
|
||||
try {
|
||||
if (client.state === "play") {
|
||||
//if (packet && packet.type === 71) {
|
||||
// console.log(packet);
|
||||
//}
|
||||
if (
|
||||
!packet ||
|
||||
packet.entityId === undefined ||
|
||||
@@ -1212,13 +1422,29 @@ async function connectToJavaServer(proxy, client) {
|
||||
}
|
||||
}
|
||||
|
||||
let tileX = packet.x / 32;
|
||||
let tileY = packet.y / 32;
|
||||
let tileZ = packet.z / 32;
|
||||
|
||||
// if (lceEntityType === 71 && itemFrameDirection !== null) {
|
||||
// if (itemFrameDirection === 0) {
|
||||
// tileZ--;
|
||||
// } else if (itemFrameDirection === 1) {
|
||||
// tileX++;
|
||||
// } else if (itemFrameDirection === 2) {
|
||||
// tileZ++;
|
||||
// } else if (itemFrameDirection === 3) {
|
||||
// tileX -= 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
const entityInfo = {
|
||||
entityId: lceEntityId,
|
||||
javaEntityId: packet.entityId,
|
||||
type: lceEntityType,
|
||||
x: packet.x / 32,
|
||||
y: packet.y / 32,
|
||||
z: packet.z / 32,
|
||||
x: tileX,
|
||||
y: tileY,
|
||||
z: tileZ,
|
||||
yaw: lceEntityType === 60 ? 0 : (packet.yaw / 256) * 360,
|
||||
pitch: lceEntityType === 60 ? 0 : (packet.pitch / 256) * 360,
|
||||
data:
|
||||
@@ -1635,12 +1861,29 @@ async function connectToJavaServer(proxy, client) {
|
||||
packet.item.blockId !== undefined &&
|
||||
packet.item.blockId !== -1
|
||||
) {
|
||||
proxy.sendSetEquippedItemPacket(
|
||||
client,
|
||||
player,
|
||||
packet.slot,
|
||||
packet.item,
|
||||
);
|
||||
const item = packet.item;
|
||||
if (item.blockId === 387) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
if (item.nbtData) {
|
||||
let isEnchanted = false;
|
||||
try {
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
(item.nbtData.value.ench ||
|
||||
item.nbtData.value.Enchantments ||
|
||||
item.nbtData.value.StoredEnchantments)
|
||||
) {
|
||||
isEnchanted = true;
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
if (isEnchanted) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
}
|
||||
proxy.sendSetEquippedItemPacket(client, player, packet.slot, item);
|
||||
} else {
|
||||
proxy.sendSetEquippedItemPacket(client, player, packet.slot, {
|
||||
blockId: -1,
|
||||
@@ -1659,12 +1902,29 @@ async function connectToJavaServer(proxy, client) {
|
||||
packet.item.blockId !== undefined &&
|
||||
packet.item.blockId !== -1
|
||||
) {
|
||||
proxy.sendSetEquippedItemPacket(
|
||||
client,
|
||||
entity,
|
||||
packet.slot,
|
||||
packet.item,
|
||||
);
|
||||
const item = packet.item;
|
||||
if (item.blockId === 387) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
if (item.nbtData) {
|
||||
let isEnchanted = false;
|
||||
try {
|
||||
if (
|
||||
item.nbtData.value &&
|
||||
(item.nbtData.value.ench ||
|
||||
item.nbtData.value.Enchantments ||
|
||||
item.nbtData.value.StoredEnchantments)
|
||||
) {
|
||||
isEnchanted = true;
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
if (isEnchanted) {
|
||||
item.enchanted = true;
|
||||
}
|
||||
}
|
||||
proxy.sendSetEquippedItemPacket(client, entity, packet.slot, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1729,7 +1989,29 @@ async function connectToJavaServer(proxy, client) {
|
||||
(m) => m.key === 10 && m.type === 5,
|
||||
);
|
||||
if (itemMetadata && itemMetadata.value) {
|
||||
proxy.sendSetItemDataPacket(client, entity, itemMetadata.value);
|
||||
const itemData = itemMetadata.value;
|
||||
if (itemData && itemData.blockId === 387) {
|
||||
itemData.enchanted = true;
|
||||
}
|
||||
if (itemData && itemData.nbtData) {
|
||||
let isEnchanted = false;
|
||||
try {
|
||||
if (
|
||||
itemData.nbtData.value &&
|
||||
(itemData.nbtData.value.ench ||
|
||||
itemData.nbtData.value.Enchantments ||
|
||||
itemData.nbtData.value.StoredEnchantments)
|
||||
) {
|
||||
isEnchanted = true;
|
||||
}
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
if (isEnchanted) {
|
||||
itemData.enchanted = true;
|
||||
}
|
||||
}
|
||||
proxy.sendSetItemDataPacket(client, entity, itemData);
|
||||
entity.waitingForItemData = false;
|
||||
}
|
||||
}
|
||||
@@ -1891,8 +2173,13 @@ async function connectToJavaServer(proxy, client) {
|
||||
let isPlayer = false;
|
||||
for (const [uuid, player] of client.javaPlayers) {
|
||||
if (player.javaEntityId === entityId && player.spawned) {
|
||||
const deathEvent = { entityId: player.entityId };
|
||||
proxy.sendEntityEventPacket(client, deathEvent, 3);
|
||||
const isDying =
|
||||
client._dyingPlayers &&
|
||||
client._dyingPlayers.has(player.javaEntityId);
|
||||
if (isDying) {
|
||||
const deathEvent = { entityId: player.entityId };
|
||||
proxy.sendEntityEventPacket(client, deathEvent, 3);
|
||||
}
|
||||
|
||||
const lceEntityId = player.entityId;
|
||||
const javaEntityId = entityId;
|
||||
@@ -2085,6 +2372,57 @@ async function connectToJavaServer(proxy, client) {
|
||||
//proxy.sendFlatChunk(client, chunkX, chunkZ);
|
||||
}
|
||||
});
|
||||
|
||||
javaClient.on("update_sign", (packet) => {
|
||||
try {
|
||||
if (!packet.location) return;
|
||||
|
||||
const x = packet.location.x;
|
||||
const y = packet.location.y;
|
||||
const z = packet.location.z;
|
||||
|
||||
const text1 = parseChatComponent(packet.text1);
|
||||
const text2 = parseChatComponent(packet.text2);
|
||||
const text3 = parseChatComponent(packet.text3);
|
||||
const text4 = parseChatComponent(packet.text4);
|
||||
|
||||
const writer = new PacketWriter();
|
||||
writer.writeInt(x);
|
||||
writer.writeShort(y);
|
||||
writer.writeInt(z);
|
||||
writer.writeBoolean(true);
|
||||
writer.writeBoolean(false);
|
||||
|
||||
writer.writeUtf(text1);
|
||||
writer.writeUtf(text2);
|
||||
writer.writeUtf(text3);
|
||||
writer.writeUtf(text4);
|
||||
|
||||
proxy.sendPacket(client, 0x82, writer.toBuffer());
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
});
|
||||
|
||||
javaClient.on("open_sign_entity", (packet) => {
|
||||
try {
|
||||
if (!packet.location) return;
|
||||
|
||||
const x = packet.location.x;
|
||||
const y = packet.location.y;
|
||||
const z = packet.location.z;
|
||||
|
||||
const writer = new PacketWriter();
|
||||
writer.writeByte(0);
|
||||
writer.writeInt(x);
|
||||
writer.writeInt(y);
|
||||
writer.writeInt(z);
|
||||
|
||||
proxy.sendPacket(client, 0x85, writer.toBuffer());
|
||||
} catch (err) {
|
||||
/* do nothing */
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function convertAndSendJavaChunk(proxy, client, javaChunk) {
|
||||
@@ -2195,6 +2533,9 @@ function convertAndSendJavaChunk(proxy, client, javaChunk) {
|
||||
} else if (javaBlockId === 32) {
|
||||
lceBlockId = 31;
|
||||
lceMetadata = 1;
|
||||
} else if (javaBlockId === 165) {
|
||||
lceBlockId = 95;
|
||||
lceMetadata = 5;
|
||||
}
|
||||
|
||||
if (lceBlockId < 0 || lceBlockId > 174) {
|
||||
|
||||
+4
-8
@@ -1,20 +1,16 @@
|
||||
/* --------------------------------------------------------------- */
|
||||
/* lanbroadcast.js */
|
||||
/* --------------------------------------------------------------- */
|
||||
const {
|
||||
MINECRAFT_NET_VERSION,
|
||||
GAME_PORT,
|
||||
PROXY_NAME,
|
||||
} = require("../constants");
|
||||
const { MINECRAFT_NET_VERSION } = require("../constants");
|
||||
|
||||
class LANBroadcast {
|
||||
constructor() {
|
||||
constructor(serverName, gamePort) {
|
||||
this.buffer = Buffer.allocUnsafe(86);
|
||||
this.buffer.writeUInt32LE(0x4d434c4e, 0);
|
||||
this.buffer.writeUInt16LE(MINECRAFT_NET_VERSION, 4);
|
||||
this.buffer.writeUInt16LE(GAME_PORT, 6);
|
||||
this.buffer.writeUInt16LE(gamePort, 6);
|
||||
|
||||
const hostName = PROXY_NAME;
|
||||
const hostName = serverName || "Minecraft Server";
|
||||
for (let i = 0; i < 32; i++) {
|
||||
const char = i < hostName.length ? hostName.charCodeAt(i) : 0;
|
||||
this.buffer.writeUInt16LE(char, 8 + i * 2);
|
||||
|
||||
+1156
-92
File diff suppressed because it is too large.
Load diff
@@ -167,12 +167,18 @@ function createBlockMapping() {
|
||||
161: 18,
|
||||
162: 17,
|
||||
163: 17,
|
||||
165: 95,
|
||||
170: 170,
|
||||
171: 171,
|
||||
172: 171,
|
||||
173: 171,
|
||||
174: 171,
|
||||
175: 31,
|
||||
193: 64,
|
||||
194: 64,
|
||||
195: 64,
|
||||
196: 64,
|
||||
197: 64,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ function createEntityTypeMapping() {
|
||||
Sheep: 91,
|
||||
Cow: 92,
|
||||
Chicken: 93,
|
||||
Rabbit: 93,
|
||||
Squid: 94,
|
||||
Wolf: 95,
|
||||
MushroomCow: 96,
|
||||
|
||||
@@ -133,6 +133,8 @@ function createItemMapping() {
|
||||
383: 383, //spawn_egg
|
||||
384: 384, //experience_bottle
|
||||
385: 385, //fire_charge
|
||||
386: 340, //writable_book -> book
|
||||
387: 340, //written_book -> book
|
||||
388: 388, //emerald
|
||||
389: 389, //item_frame
|
||||
390: 390, //flower_pot
|
||||
@@ -159,6 +161,20 @@ function createItemMapping() {
|
||||
419: 419, //diamond_horse_armor
|
||||
420: 420, //lead
|
||||
421: 421, //name_tag
|
||||
423: 363, //raw_mutton -> raw_beef
|
||||
424: 364, //cooked_mutton -> cooked_beef
|
||||
411: 363, //raw_rabbit -> raw_beef
|
||||
412: 364, //cooked_rabbit -> cooked_beef
|
||||
413: 282, //rabbit_stew -> mushroom_stew
|
||||
414: 371, //rabbit_foot -> gold_nugget
|
||||
415: 334, //rabbit_hide -> leather
|
||||
165: 95, //slime_block -> lime_stained_glass
|
||||
387: 340, //written_book -> book
|
||||
427: 324, //spruce_door -> oak_door
|
||||
428: 324, //birch_door -> oak_door
|
||||
429: 324, //jungle_door -> oak_door
|
||||
430: 324, //acacia_door -> oak_door
|
||||
431: 324, //dark_oak_door -> oak_door
|
||||
2256: 2256, //record_13
|
||||
2257: 2257, //record_cat
|
||||
2258: 2258, //record_blocks
|
||||
|
||||
@@ -4,7 +4,43 @@
|
||||
//all of the crafting recipes that are sent from the client converted into a java recipe grid.
|
||||
//this was absolute fucking torture to write, thanks mojang for not using recipe ids in java edition crafting until 1.12!
|
||||
|
||||
//unfinised as of 3/9/2026 (MM/DD/YY)
|
||||
//DO NOT BEAUTIFY THIS FILE!!
|
||||
//everything should match 1.8 Java IDs except:
|
||||
//any_plank
|
||||
//any_slab
|
||||
//cocoa_beans
|
||||
//inc_sac
|
||||
//red_dye
|
||||
//green_dye
|
||||
//lapis
|
||||
//purple_dye
|
||||
//cyan_dye
|
||||
//light_gray_dye
|
||||
//gray_dye
|
||||
//pink_dye
|
||||
//lime_dye
|
||||
//yellow_dye
|
||||
//light_blue_dye
|
||||
//magenta_dye
|
||||
//orange_dye
|
||||
//bone_meal
|
||||
//dandelion
|
||||
//rose
|
||||
//orange_wool
|
||||
//magenta_wool
|
||||
//light_blue_wool
|
||||
//yellow_wool
|
||||
//lime_wool
|
||||
//pink_wool
|
||||
//gray_wool
|
||||
//light_gray_wool
|
||||
//cyan_wool
|
||||
//purple_wool
|
||||
//blue_wool
|
||||
//brown_wool
|
||||
//green_wool
|
||||
//red_wool
|
||||
//black_wool
|
||||
|
||||
module.exports = {
|
||||
//page 1
|
||||
@@ -263,7 +299,65 @@ module.exports = {
|
||||
"quartz_block", "quartz_block", "none",
|
||||
"quartz_block", "quartz_block", "quartz_block"
|
||||
],
|
||||
//next: slabs
|
||||
|
||||
|
||||
|
||||
162: [
|
||||
"sandstone", "sandstone", "sandstone",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
163: [
|
||||
"stone", "stone", "stone",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
164: [
|
||||
"cobblestone", "cobblestone", "cobblestone",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
165: [
|
||||
"brick_block", "brick_block", "brick_block",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
166: [
|
||||
"stone_bricks", "stone_bricks", "stone_bricks",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
167: [
|
||||
"nether_brick", "nether_brick", "nether_brick",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
168: [
|
||||
"quartz_block", "quartz_block", "quartz_block",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
169: [
|
||||
"oak_planks", "oak_planks", "oak_planks",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
170: [
|
||||
"birch_planks", "birch_planks", "birch_planks",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
171: [
|
||||
"spruce_planks", "spruce_planks", "spruce_planks",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
172: [
|
||||
"jungle_planks", "jungle_planks", "jungle_planks",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -581,10 +675,881 @@ module.exports = {
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
31: [
|
||||
"melon", "melon", "melon",
|
||||
"melon", "melon", "melon",
|
||||
"melon", "melon", "melon"
|
||||
],
|
||||
|
||||
|
||||
|
||||
32: [
|
||||
"melon", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
33: [
|
||||
"pumpkin", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
34: [
|
||||
"pumkpkin", "sugar", "none",
|
||||
"egg", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
36: [
|
||||
"spider_eye", "brown_mushroom", "none",
|
||||
"sugar", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
37: [
|
||||
"blaze_rod", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
37: [
|
||||
"blaze_powder", "slime_ball", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
173: [
|
||||
"milk_bucket", "milk_bucket", "milk_bucket",
|
||||
"sugar", "egg", "sugar",
|
||||
"wheat", "wheat", "wheat"
|
||||
],
|
||||
|
||||
|
||||
|
||||
174: [
|
||||
"sugar", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
188: [
|
||||
"wheat", "wheat", "wheat",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none"
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//page 4
|
||||
77: [
|
||||
"leather", "leather", "leather",
|
||||
"leather", "none", "leather",
|
||||
"none", "none", "none",
|
||||
],
|
||||
81: [
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"none", "none", "none",
|
||||
],
|
||||
85: [
|
||||
"diamond", "diamond", "diamond",
|
||||
"diamond", "none", "diamond",
|
||||
"none", "none", "none",
|
||||
],
|
||||
89: [
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
78: [
|
||||
"leather", "none", "leather",
|
||||
"leather", "leather", "leather",
|
||||
"leather", "leather", "leather",
|
||||
],
|
||||
82: [
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
],
|
||||
86: [
|
||||
"diamond", "none", "diamond",
|
||||
"diamond", "diamond", "diamond",
|
||||
"diamond", "diamond", "diamond",
|
||||
],
|
||||
90: [
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
],
|
||||
|
||||
|
||||
|
||||
79: [
|
||||
"leather", "leather", "leather",
|
||||
"leather", "none", "leather",
|
||||
"leather", "none", "leather",
|
||||
],
|
||||
83: [
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
],
|
||||
87: [
|
||||
"diamond", "diamond", "diamond",
|
||||
"diamond", "none", "diamond",
|
||||
"diamond", "none", "diamond",
|
||||
],
|
||||
91: [
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
],
|
||||
|
||||
|
||||
|
||||
80: [
|
||||
"none", "none", "none",
|
||||
"leather", "none", "leather",
|
||||
"leather", "none", "leather",
|
||||
],
|
||||
84: [
|
||||
"none", "none", "none",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
],
|
||||
88: [
|
||||
"none", "none", "none",
|
||||
"diamond", "none", "diamond",
|
||||
"diamond", "none", "diamond",
|
||||
],
|
||||
92: [
|
||||
"none", "none", "none",
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//page 5
|
||||
52: [
|
||||
"none", "redstone", "none",
|
||||
"redstone", "glowstone", "redstone",
|
||||
"none", "redstone", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
53: [
|
||||
"glass", "glass", "glass",
|
||||
"glass", "nether_star", "glass",
|
||||
"obsidian", "obsidian", "obsidian",
|
||||
],
|
||||
|
||||
|
||||
|
||||
204: [
|
||||
"stick", "none", "none",
|
||||
"cobblestone", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
205: [
|
||||
"iron_ingot", "none", "none",
|
||||
"stick", "none", "none",
|
||||
"oak_planks", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
206: [
|
||||
"redstone", "none", "none",
|
||||
"stick", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
207: [
|
||||
"redstone_torch", "redstone", "redstone_torch",
|
||||
"stone", "stone", "stone",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
208: [
|
||||
"none", "redstone_torch", "none",
|
||||
"redstone_torch", "quartz", "redstone_torch",
|
||||
"stone", "stone", "stone",
|
||||
],
|
||||
|
||||
|
||||
|
||||
209: [
|
||||
"glass", "glass", "glass",
|
||||
"quartz", "quartz", "quartz",
|
||||
"any_slab", "any_slab", "any_slab",
|
||||
],
|
||||
|
||||
|
||||
|
||||
210: [
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "chest", "iron_ingot",
|
||||
"none", "iron_ingot", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
224: [
|
||||
"cobblestone", "cobblestone", "cobblestone",
|
||||
"cobblestone", "bow", "cobblestone",
|
||||
"cobblestone", "redstone", "cobblestone",
|
||||
],
|
||||
225: [
|
||||
"cobblestone", "cobblestone", "cobblestone",
|
||||
"cobblestone", "none", "cobblestone",
|
||||
"cobblestone", "redstone", "cobblestone",
|
||||
],
|
||||
|
||||
|
||||
|
||||
218: [
|
||||
"stone", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
219: [
|
||||
"any_plank", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
220: [
|
||||
"any_plank", "any_plank", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
221: [
|
||||
"stone", "stone", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
222: [
|
||||
"iron_ingot", "iron_ingot", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
223: [
|
||||
"gold_ingot", "gold_ingot", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
232: [
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"any_plank", "redstone", "any_plank",
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
],
|
||||
|
||||
|
||||
|
||||
255: [
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"cobblestone", "iron_ingot", "cobblestone",
|
||||
"cobblestone", "redstone", "cobblestone",
|
||||
],
|
||||
256: [
|
||||
"slime_ball", "none", "none",
|
||||
"piston", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//page 6
|
||||
175: [
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "stick", "iron_ingot",
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
],
|
||||
176: [
|
||||
"gold_ingot", "none", "gold_ingot",
|
||||
"gold_ingot", "stick", "gold_ingot",
|
||||
"gold_ingot", "redstone", "gold_ingot",
|
||||
],
|
||||
178: [
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "stone_pressure_plate", "iron_ingot",
|
||||
"iron_ingot", "redstone", "iron_ingot",
|
||||
],
|
||||
|
||||
|
||||
|
||||
177: [
|
||||
"iron_ingot", "stick", "iron_ingot",
|
||||
"iron_ingot", "redstone_torch", "iron_ingot",
|
||||
"iron_ingot", "stick", "iron_ingot",
|
||||
],
|
||||
|
||||
|
||||
|
||||
179: [
|
||||
"iron_ingot", "none", "iron_ingot",
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
180: [
|
||||
"chest", "none", "none",
|
||||
"minecart", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
181: [
|
||||
"furnace", "none", "none",
|
||||
"minecart", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
182: [
|
||||
"tnt", "none", "none",
|
||||
"minecart", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
184: [
|
||||
"any_plank", "none", "any_plank",
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//page 7
|
||||
50: [
|
||||
"glass", "glass", "glass",
|
||||
"glass", "glass", "glass",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
93: [
|
||||
"inc_sac", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
95: [
|
||||
"red_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
97: [
|
||||
"green_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
99: [
|
||||
"cocoa_beans", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
101: [
|
||||
"lapis", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
103: [
|
||||
"purple_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
105: [
|
||||
"cyan_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
105: [
|
||||
"cyan_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
107: [
|
||||
"light_gray_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
107: [
|
||||
"gray_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
111: [
|
||||
"pink_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
113: [
|
||||
"lime_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
115: [
|
||||
"yellow_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
117: [
|
||||
"light_blue_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
119: [
|
||||
"magenta_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
121: [
|
||||
"orange_dye", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
123: [
|
||||
"bone_meal", "wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
160: [
|
||||
"string", "string", "none",
|
||||
"string", "string", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
94: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "inc_sac", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
96: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "red_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
98: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "green_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
100: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "cocoa_beans", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
102: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "lapis", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
104: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "purple_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
106: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "cyan_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
108: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "light_gray_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
110: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "gray_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
112: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "pink_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
114: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "lime_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
116: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "yellow_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
118: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "light_blue_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
120: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "magenta_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
122: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "orange_dye", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
124: [
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
"hardened_clay", "bone_meal", "hardened_clay",
|
||||
"hardened_clay", "hardened_clay", "hardened_clay",
|
||||
],
|
||||
|
||||
|
||||
|
||||
125: [
|
||||
"dandelion", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
126: [
|
||||
"rose", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
127: [
|
||||
"bone", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
128: [
|
||||
"red_dye", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
129: [
|
||||
"red_dye", "yellow_dye", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
130: [
|
||||
"green_dye", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
131: [
|
||||
"inc_sac", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
132: [
|
||||
"gray_dye", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
133: [
|
||||
"light_gray_dye", "bone_meal", "none",
|
||||
"bone_meal", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
134: [
|
||||
"lapis", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
135: [
|
||||
"lapis", "green_dye", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
136: [
|
||||
"lapis", "red_dye", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
137: [
|
||||
"purple_dye", "pink_dye", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
138: [
|
||||
"lapis", "red_dye", "none",
|
||||
"pink_dye", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
139: [
|
||||
"lapis", "red_dye", "none",
|
||||
"red_dye", "bone_meal", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
245: [
|
||||
"lapis_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
140: [
|
||||
"wool", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
141: [
|
||||
"orange_wool", "orange_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
142: [
|
||||
"magenta_wool", "magenta_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
143: [
|
||||
"light_blue_wool", "light_blue_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
144: [
|
||||
"yellow_wool", "yellow_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
145: [
|
||||
"lime_wool", "lime_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
146: [
|
||||
"pink_wool", "pink_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
147: [
|
||||
"gray_wool", "gray_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
148: [
|
||||
"light_gray_wool", "light_gray_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
149: [
|
||||
"cyan_wool", "cyan_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
150: [
|
||||
"purple_wool", "purple_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
151: [
|
||||
"blue_wool", "blue_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
152: [
|
||||
"brown_wool", "brown_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
153: [
|
||||
"green_wool", "green_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
154: [
|
||||
"red_wool", "red_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
155: [
|
||||
"black_wool", "black_wool", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
199: [
|
||||
"brick", "none", "brick",
|
||||
"none", "brick", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
229: [
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"any_plank", "diamond", "any_plank",
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
],
|
||||
|
||||
|
||||
|
||||
230: [
|
||||
"paper", "paper", "none",
|
||||
"paper", "leather", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
231: [
|
||||
"sugar_cane", "sugar_cane", "sugar_cane",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
233: [
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"book", "book", "book",
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
],
|
||||
|
||||
|
||||
|
||||
234: [
|
||||
"stick", "stick", "stick",
|
||||
"stick", "any_wool", "stick",
|
||||
"stick", "stick", "stick",
|
||||
],
|
||||
235: [
|
||||
"stick", "stick", "stick",
|
||||
"stick", "leather", "stick",
|
||||
"stick", "stick", "stick",
|
||||
],
|
||||
254: [
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"any_plank", "any_plank", "any_plank",
|
||||
"none", "stick", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
236: [
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
"gold_ingot", "gold_ingot", "gold_ingot",
|
||||
],
|
||||
238: [
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
"iron_ingot", "iron_ingot", "iron_ingot",
|
||||
],
|
||||
240: [
|
||||
"diamond", "diamond", "diamond",
|
||||
"diamond", "diamond", "diamond",
|
||||
"diamond", "diamond", "diamond",
|
||||
],
|
||||
242: [
|
||||
"emerald", "emerald", "emerald",
|
||||
"emerald", "emerald", "emerald",
|
||||
"emerald", "emerald", "emerald",
|
||||
],
|
||||
244: [
|
||||
"lapis", "lapis", "lapis",
|
||||
"lapis", "lapis", "lapis",
|
||||
"lapis", "lapis", "none",
|
||||
],
|
||||
246: [
|
||||
"redstone", "redstone", "redstone",
|
||||
"redstone", "redstone", "redstone",
|
||||
"redstone", "redstone", "redstone",
|
||||
],
|
||||
248: [
|
||||
"coal", "coal", "coal",
|
||||
"coal", "coal", "coal",
|
||||
"coal", "coal", "coal",
|
||||
],
|
||||
250: [
|
||||
"wheat", "wheat", "wheat",
|
||||
"wheat", "wheat", "wheat",
|
||||
"wheat", "wheat", "wheat",
|
||||
],
|
||||
|
||||
|
||||
|
||||
237: [
|
||||
"gold_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
239: [
|
||||
"iron_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
241: [
|
||||
"diamond_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
243: [
|
||||
"emerald_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
247: [
|
||||
"redstone_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
251: [
|
||||
"hay_block", "none", "none",
|
||||
"none", "none", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
|
||||
|
||||
|
||||
257: [
|
||||
"none", "paper", "none",
|
||||
"none", "gunpowder", "none",
|
||||
"none", "none", "none",
|
||||
],
|
||||
};
|
||||
/* --------------------------------------------------------------- */
|
||||
@@ -58,6 +58,17 @@ class PacketReader {
|
||||
return str;
|
||||
}
|
||||
|
||||
readUtf() {
|
||||
const length = this.readShort();
|
||||
let str = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
const charCode = this.buffer.readUInt16BE(this.offset);
|
||||
this.offset += 2;
|
||||
str += String.fromCharCode(charCode);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
readDouble() {
|
||||
const value = this.buffer.readDoubleBE(this.offset);
|
||||
this.offset += 8;
|
||||
|
||||
@@ -23,9 +23,21 @@ function sendContainerOpenPacket(proxy, client, packet) {
|
||||
const windowType = packet.inventoryType || packet.windowType;
|
||||
const lceType = windowTypeMapping[windowType] || 0;
|
||||
const containerId = packet.windowId;
|
||||
const title = packet.windowTitle
|
||||
? JSON.parse(packet.windowTitle).text || ""
|
||||
: "";
|
||||
|
||||
let title = "";
|
||||
if (packet.windowTitle) {
|
||||
try {
|
||||
const parsed = JSON.parse(packet.windowTitle);
|
||||
if (parsed.extra && parsed.extra.length > 0 && parsed.extra[0].text) {
|
||||
title = parsed.extra[0].text;
|
||||
} else if (parsed.text) {
|
||||
title = parsed.text;
|
||||
}
|
||||
} catch (err) {
|
||||
title = packet.windowTitle;
|
||||
}
|
||||
}
|
||||
|
||||
const size = packet.slotCount || 27;
|
||||
const customName = title.length > 0;
|
||||
|
||||
@@ -44,7 +56,11 @@ function sendContainerOpenPacket(proxy, client, packet) {
|
||||
writer.writeUtf(title);
|
||||
}
|
||||
|
||||
proxy.sendPacket(client, 0x64, writer.toBuffer());
|
||||
const buffer = writer.toBuffer();
|
||||
const sendTime = Date.now();
|
||||
|
||||
client._lastContainerOpenTime = sendTime;
|
||||
proxy.sendPacket(client, 0x64, buffer);
|
||||
}
|
||||
|
||||
function sendVillagerTrades(proxy, client, windowId, packetData) {
|
||||
|
||||
@@ -336,16 +336,9 @@ function sendEntityMetadataPacket(proxy, client, entity, metadata) {
|
||||
|
||||
for (const item of metadata) {
|
||||
if (!item || item.type === undefined || item.key === undefined) {
|
||||
console.error(
|
||||
`[METADATA ERROR] entityId=${entity.entityId} invalid metadata item:`,
|
||||
JSON.stringify(item),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (item.type < 0 || item.type > 5) {
|
||||
console.error(
|
||||
`[METADATA ERROR] entityId=${entity.entityId} invalid type=${item.type} key=${item.key}`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (item.type === 5) {
|
||||
@@ -471,10 +464,27 @@ function sendSetEquippedItemPacket(proxy, client, entity, slot, item) {
|
||||
return;
|
||||
}
|
||||
|
||||
const javaItemId = item.blockId;
|
||||
let javaItemId = item.blockId;
|
||||
const count = item.itemCount || 1;
|
||||
let damage = item.itemDamage || 0;
|
||||
|
||||
if (javaItemId === 162) {
|
||||
javaItemId = 35;
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
if (javaItemId === 5 && (damage === 4 || damage === 5)) {
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
if (javaItemId === 383 && damage === 101) {
|
||||
damage = 93;
|
||||
}
|
||||
|
||||
if (javaItemId === 165) {
|
||||
damage = 5;
|
||||
}
|
||||
|
||||
const lceItemId = proxy.mapJavaItemToLCE(javaItemId);
|
||||
|
||||
if (lceItemId === 1 && javaItemId !== 1) {
|
||||
@@ -502,7 +512,7 @@ function sendSetEquippedItemPacket(proxy, client, entity, slot, item) {
|
||||
return;
|
||||
}
|
||||
|
||||
writer.writeShort(-1);
|
||||
proxy.writeItemNBT(writer, item);
|
||||
|
||||
proxy.sendPacket(client, 0x05, writer.toBuffer());
|
||||
}
|
||||
@@ -554,7 +564,27 @@ function sendTileUpdatePacket(proxy, client, x, y, z, blockId, metadata) {
|
||||
}
|
||||
|
||||
function sendSetItemDataPacket(proxy, client, entity, itemData) {
|
||||
const lceItemId = proxy.mapJavaItemToLCE(itemData.blockId);
|
||||
let damage = itemData.itemDamage || 0;
|
||||
let javaItemId = itemData.blockId;
|
||||
|
||||
if (javaItemId === 162) {
|
||||
javaItemId = 35;
|
||||
damage = 1;
|
||||
}
|
||||
|
||||
if (javaItemId === 5 && (damage === 4 || damage === 5)) {
|
||||
damage = 0;
|
||||
}
|
||||
|
||||
if (javaItemId === 383 && damage === 101) {
|
||||
damage = 93;
|
||||
}
|
||||
|
||||
if (javaItemId === 165) {
|
||||
damage = 5;
|
||||
}
|
||||
|
||||
const lceItemId = proxy.mapJavaItemToLCE(javaItemId);
|
||||
|
||||
if (lceItemId === -1 || lceItemId === 0) {
|
||||
return;
|
||||
@@ -567,9 +597,26 @@ function sendSetItemDataPacket(proxy, client, entity, itemData) {
|
||||
|
||||
writer.writeShort(lceItemId);
|
||||
writer.writeByte(itemData.itemCount);
|
||||
writer.writeShort(itemData.itemDamage);
|
||||
writer.writeShort(damage);
|
||||
|
||||
writer.writeShort(-1);
|
||||
proxy.writeItemNBT(writer, itemData);
|
||||
|
||||
writer.writeByte(0x7f);
|
||||
|
||||
const payload = writer.toBuffer();
|
||||
|
||||
proxy.sendPacket(client, 0x28, payload);
|
||||
}
|
||||
|
||||
function sendSetItemFrameDataPacket(proxy, client, entity, itemData, rotation) {
|
||||
const writer = new PacketWriter();
|
||||
writer.writeInt(entity.entityId);
|
||||
|
||||
writer.writeByte((5 << 5) | 2);
|
||||
proxy.writeItem(writer, itemData);
|
||||
|
||||
writer.writeByte((0 << 5) | 3);
|
||||
writer.writeByte(rotation & 0xff);
|
||||
|
||||
writer.writeByte(0x7f);
|
||||
|
||||
@@ -642,6 +689,7 @@ module.exports = {
|
||||
sendEntityEventPacket,
|
||||
sendSetEquippedItemPacket,
|
||||
sendSetItemDataPacket,
|
||||
sendSetItemFrameDataPacket,
|
||||
sendSetEntityDataPacket,
|
||||
sendUpdateAttributesPacket,
|
||||
sendSetEntityLinkPacket,
|
||||
|
||||
@@ -64,6 +64,15 @@ class PacketWriter {
|
||||
this.buffers.push(utf8Buffer);
|
||||
}
|
||||
|
||||
writeUtf(str) {
|
||||
this.writeShort(str.length);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const buf = Buffer.allocUnsafe(2);
|
||||
buf.writeUInt16BE(str.charCodeAt(i), 0);
|
||||
this.buffers.push(buf);
|
||||
}
|
||||
}
|
||||
|
||||
writeString(str) {
|
||||
this.writeShort(str.length);
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
|
||||
+113
-3
@@ -67,8 +67,52 @@ function readItem(reader) {
|
||||
}
|
||||
|
||||
function writeItemNBT(writer, item) {
|
||||
writer.writeShort(-1);
|
||||
return;
|
||||
if (!item || (!item.displayName && !item.enchanted)) {
|
||||
writer.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const nbt = require("prismarine-nbt");
|
||||
|
||||
const nbtValue = {};
|
||||
|
||||
if (item.displayName && item.displayName.length > 0) {
|
||||
const cleanedName = item.displayName.replace(/§[0-9a-fk-or]/gi, "");
|
||||
nbtValue.display = {
|
||||
type: "compound",
|
||||
value: {
|
||||
Name: {
|
||||
type: "string",
|
||||
value: cleanedName,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (item.enchanted) {
|
||||
nbtValue.ench = {
|
||||
type: "list",
|
||||
value: {
|
||||
type: "compound",
|
||||
value: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const nbtData = {
|
||||
type: "compound",
|
||||
name: "",
|
||||
value: nbtValue,
|
||||
};
|
||||
|
||||
const nbtBuffer = nbt.writeUncompressed(nbtData, "big");
|
||||
|
||||
writer.writeShort(nbtBuffer.length);
|
||||
writer.writeBytes(nbtBuffer);
|
||||
} catch (err) {
|
||||
writer.writeShort(-1);
|
||||
}
|
||||
}
|
||||
|
||||
function writeItem(writer, item, mapJavaItemToLCE) {
|
||||
@@ -94,10 +138,76 @@ function writeItem(writer, item, mapJavaItemToLCE) {
|
||||
return;
|
||||
}
|
||||
|
||||
let lceItemId = mapJavaItemToLCE(javaItemId);
|
||||
let auxValue =
|
||||
item.itemDamage !== undefined ? item.itemDamage : item.metadata || 0;
|
||||
|
||||
if (javaItemId === 162) {
|
||||
javaItemId = 35;
|
||||
auxValue = 1;
|
||||
if (!item.displayName) {
|
||||
item.displayName = "Acacia Wood";
|
||||
}
|
||||
}
|
||||
|
||||
let lceItemId = mapJavaItemToLCE(javaItemId);
|
||||
|
||||
if (javaItemId === 5 && auxValue === 4) {
|
||||
auxValue = 0;
|
||||
if (!item.displayName) {
|
||||
item.displayName = "Acacia Wood Planks";
|
||||
}
|
||||
}
|
||||
|
||||
if (javaItemId === 5 && auxValue === 5) {
|
||||
auxValue = 0;
|
||||
if (!item.displayName) {
|
||||
item.displayName = "Dark Oak Wood Planks";
|
||||
}
|
||||
}
|
||||
|
||||
if (javaItemId === 383 && auxValue === 101) {
|
||||
auxValue = 93;
|
||||
if (!item.displayName) {
|
||||
item.displayName = "Rabbit Spawn Egg";
|
||||
}
|
||||
}
|
||||
|
||||
const customItemNames = {
|
||||
386: "Book and Quill",
|
||||
427: "Spruce Door",
|
||||
428: "Birch Door",
|
||||
429: "Jungle Door",
|
||||
430: "Acacia Door",
|
||||
431: "Dark Oak Door",
|
||||
423: "Raw Mutton",
|
||||
424: "Cooked Mutton",
|
||||
411: "Raw Rabbit",
|
||||
412: "Cooked Rabbit",
|
||||
413: "Rabbit Stew",
|
||||
414: "Rabbit Foot",
|
||||
415: "Rabbit Hide",
|
||||
165: "Slime Block",
|
||||
};
|
||||
|
||||
if (customItemNames[javaItemId] && !item.displayName) {
|
||||
item.displayName = customItemNames[javaItemId];
|
||||
}
|
||||
|
||||
if (javaItemId === 165) {
|
||||
auxValue = 5;
|
||||
}
|
||||
|
||||
if (javaItemId === 387) {
|
||||
let authorName = "Unknown";
|
||||
if (item.nbtData && item.nbtData.value && item.nbtData.value.author) {
|
||||
authorName = item.nbtData.value.author.value || "Unknown";
|
||||
}
|
||||
if (!item.displayName) {
|
||||
item.displayName = `Written Book (by ${authorName})`;
|
||||
}
|
||||
item.enchanted = true;
|
||||
}
|
||||
|
||||
if (
|
||||
lceItemId === undefined ||
|
||||
lceItemId === null ||
|
||||
|
||||
@@ -111,9 +111,49 @@ function generateCustomSkinName(playerName) {
|
||||
return `ugcskin${skinId.toString(16).toUpperCase().padStart(8, "0")}.png`;
|
||||
}
|
||||
|
||||
function generateCustomCapeName(playerName) {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < playerName.length; i++) {
|
||||
hash = (hash << 5) - hash + playerName.charCodeAt(i);
|
||||
hash = hash & hash;
|
||||
}
|
||||
const capeId = (Math.abs(hash) & 0x7fffffe0) | 0x20;
|
||||
return `ugccape${capeId.toString(16).toUpperCase().padStart(8, "0")}.png`;
|
||||
}
|
||||
|
||||
function downloadCape(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (skinCache.has(url)) {
|
||||
resolve(skinCache.get(url));
|
||||
return;
|
||||
}
|
||||
|
||||
const protocol = url.startsWith("https") ? https : http;
|
||||
|
||||
protocol
|
||||
.get(url, (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(`HTTP ${res.statusCode}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const chunks = [];
|
||||
res.on("data", (chunk) => chunks.push(chunk));
|
||||
res.on("end", () => {
|
||||
const capeData = Buffer.concat(chunks);
|
||||
skinCache.set(url, capeData);
|
||||
resolve(capeData);
|
||||
});
|
||||
})
|
||||
.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
downloadSkin,
|
||||
downloadCape,
|
||||
generateCustomSkinName,
|
||||
generateCustomCapeName,
|
||||
skinCache,
|
||||
};
|
||||
/* --------------------------------------------------------------- */
|
||||
Reference in new issue
Block a user