mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-02 07:35:08 +02:00
extend item ids to 16 bits
This commit is contained in:
6
main.c
6
main.c
@@ -64,8 +64,10 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
short _x = x / 16, _z = z / 16;
|
short _x = x / 16, _z = z / 16;
|
||||||
|
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
uint8_t *inventory = getPlayerInventory(client_fd);
|
||||||
for (uint8_t i = 0; i < 82; i += 2) {
|
uint16_t item;
|
||||||
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i / 2), inventory[i + 1], inventory[i]);
|
for (uint8_t i = 0; i < 123; i += 3) {
|
||||||
|
memcpy(&item, inventory + i, 2);
|
||||||
|
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i / 3), inventory[i + 2], item);
|
||||||
}
|
}
|
||||||
sc_setHeldItem(client_fd, *(inventory - 1));
|
sc_setHeldItem(client_fd, *(inventory - 1));
|
||||||
|
|
||||||
|
@@ -20,6 +20,6 @@ uint8_t player_data[(
|
|||||||
2 + // Z position (short)
|
2 + // Z position (short)
|
||||||
2 + // Angles (both, i8)
|
2 + // Angles (both, i8)
|
||||||
1 + // Hotbar slot
|
1 + // Hotbar slot
|
||||||
82 // Inventory
|
123 // Inventory (u16 id, u8 count)
|
||||||
) * MAX_PLAYERS];
|
) * MAX_PLAYERS];
|
||||||
int player_data_size = 16 + 4 + 2 + 2 + 2 + 2 + 1 + 82;
|
int player_data_size = 16 + 4 + 2 + 2 + 2 + 2 + 1 + 123;
|
||||||
|
@@ -32,7 +32,7 @@ extern uint8_t player_data[(
|
|||||||
2 + // Z position (short)
|
2 + // Z position (short)
|
||||||
2 + // Angles (both, i8)
|
2 + // Angles (both, i8)
|
||||||
1 + // Hotbar slot
|
1 + // Hotbar slot
|
||||||
82 // Inventory
|
123 // Inventory (u16 id, u8 count)
|
||||||
) * MAX_PLAYERS];
|
) * MAX_PLAYERS];
|
||||||
extern int player_data_size;
|
extern int player_data_size;
|
||||||
|
|
||||||
|
@@ -314,7 +314,7 @@ int sc_keepAlive (int client_fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// S->C Set Container Slot
|
// S->C Set Container Slot
|
||||||
int sc_setContainerSlot (int client_fd, int container, uint16_t slot, uint8_t count, uint8_t item) {
|
int sc_setContainerSlot (int client_fd, int container, uint16_t slot, uint8_t count, uint16_t item) {
|
||||||
|
|
||||||
writeVarInt(client_fd,
|
writeVarInt(client_fd,
|
||||||
1 +
|
1 +
|
||||||
@@ -361,7 +361,7 @@ int cs_playerAction (int client_fd) {
|
|||||||
// block was mined in survival
|
// block was mined in survival
|
||||||
|
|
||||||
uint8_t block = getBlockAt(x, y, z);
|
uint8_t block = getBlockAt(x, y, z);
|
||||||
uint8_t item;
|
uint16_t item, tmp;
|
||||||
|
|
||||||
if (block == B_oak_leaves) {
|
if (block == B_oak_leaves) {
|
||||||
if (sequence % 40 < 2) item = I_oak_sapling;
|
if (sequence % 40 < 2) item = I_oak_sapling;
|
||||||
@@ -373,16 +373,17 @@ int cs_playerAction (int client_fd) {
|
|||||||
makeBlockChange(x, y, z, 0);
|
makeBlockChange(x, y, z, 0);
|
||||||
|
|
||||||
int slot_pair = -1;
|
int slot_pair = -1;
|
||||||
for (int i = 0; i < 36 * 2; i += 2) {
|
for (int i = 0; i < 36 * 3; i += 3) {
|
||||||
if (inventory[i] == item && inventory[i+1] < 64) {
|
memcpy(&tmp, inventory + i, 2);
|
||||||
|
if (tmp == item && inventory[i+2] < 64) {
|
||||||
slot_pair = i;
|
slot_pair = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot_pair == -1) {
|
if (slot_pair == -1) {
|
||||||
for (int i = 0; i < 36 * 2; i += 2) {
|
for (int i = 0; i < 36 * 3; i += 3) {
|
||||||
if (inventory[i] == 0 || inventory[i+1] == 0) {
|
if ((inventory[i] == 0 && inventory[i + 1] == 0) || inventory[i+2] == 0) {
|
||||||
slot_pair = i;
|
slot_pair = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -390,10 +391,9 @@ int cs_playerAction (int client_fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item && slot_pair != -1) {
|
if (item && slot_pair != -1) {
|
||||||
uint8_t slot = serverSlotToClientSlot(slot_pair / 2);
|
uint8_t slot = serverSlotToClientSlot(slot_pair / 3);
|
||||||
inventory[slot_pair] = item;
|
memcpy(inventory + slot_pair, &item, 2);
|
||||||
inventory[slot_pair + 1] ++;
|
sc_setContainerSlot(client_fd, 0, slot, ++inventory[slot_pair + 2], item);
|
||||||
sc_setContainerSlot(client_fd, 0, slot, inventory[slot_pair + 1], item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -429,11 +429,11 @@ int cs_useItemOn (int client_fd) {
|
|||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
uint8_t *inventory = getPlayerInventory(client_fd);
|
||||||
// then, get pointer to selected hotbar slot
|
// then, get pointer to selected hotbar slot
|
||||||
// the hotbar position is in address (inventory - 1)
|
// the hotbar position is in address (inventory - 1)
|
||||||
uint8_t *slot = inventory + (*(inventory - 1)) * 2;
|
uint8_t *slot = inventory + (*(inventory - 1)) * 3;
|
||||||
// the inventory is split into id-amount pairs, get the amount address
|
// the inventory is split into id-amount pairs, get the amount address
|
||||||
uint8_t *amount = slot + 1;
|
uint8_t *amount = slot + 2;
|
||||||
// convert the item id to a block id
|
// convert the item id to a block id
|
||||||
uint8_t block = I_to_B[*slot];
|
uint8_t block = I_to_B[*(uint16_t *)slot];
|
||||||
|
|
||||||
// if the selected item doesn't correspond to a block, exit
|
// if the selected item doesn't correspond to a block, exit
|
||||||
if (block == 0) return 0;
|
if (block == 0) return 0;
|
||||||
@@ -471,7 +471,8 @@ int cs_clickContainer (int client_fd) {
|
|||||||
|
|
||||||
uint8_t *inventory = getPlayerInventory(client_fd);
|
uint8_t *inventory = getPlayerInventory(client_fd);
|
||||||
uint8_t slot, count;
|
uint8_t slot, count;
|
||||||
int item, tmp;
|
uint16_t item;
|
||||||
|
int tmp;
|
||||||
|
|
||||||
for (int i = 0; i < changes_count; i ++) {
|
for (int i = 0; i < changes_count; i ++) {
|
||||||
|
|
||||||
@@ -479,8 +480,9 @@ int cs_clickContainer (int client_fd) {
|
|||||||
|
|
||||||
if (!readByte(client_fd)) { // no item?
|
if (!readByte(client_fd)) { // no item?
|
||||||
if (slot != 255) {
|
if (slot != 255) {
|
||||||
inventory[slot * 2] = 0;
|
inventory[slot * 3] = 0;
|
||||||
inventory[slot * 2 + 1] = 0;
|
inventory[slot * 3 + 1] = 0;
|
||||||
|
inventory[slot * 3 + 2] = 0;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -495,8 +497,8 @@ int cs_clickContainer (int client_fd) {
|
|||||||
recv(client_fd, recv_buffer, tmp, MSG_WAITALL);
|
recv(client_fd, recv_buffer, tmp, MSG_WAITALL);
|
||||||
|
|
||||||
if (item <= 255 && count > 0) {
|
if (item <= 255 && count > 0) {
|
||||||
inventory[slot * 2] = (uint8_t)item;
|
memcpy(inventory + slot * 3, &item, 2);
|
||||||
inventory[slot * 2 + 1] = count;
|
inventory[slot * 3 + 2] = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ int sc_startWaitingForChunks (int client_fd);
|
|||||||
int sc_setCenterChunk (int client_fd, int x, int y);
|
int sc_setCenterChunk (int client_fd, int x, int y);
|
||||||
int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z);
|
int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z);
|
||||||
int sc_keepAlive (int client_fd);
|
int sc_keepAlive (int client_fd);
|
||||||
int sc_setContainerSlot (int client_fd, int container, uint16_t slot, uint8_t count, uint8_t item);
|
int sc_setContainerSlot (int client_fd, int container, uint16_t slot, uint8_t count, uint16_t item);
|
||||||
int sc_setHeldItem (int client_fd, uint8_t slot);
|
int sc_setHeldItem (int client_fd, uint8_t slot);
|
||||||
int sc_registries(int client_fd);
|
int sc_registries(int client_fd);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user