mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 19:20:54 +00:00
start fixing inventory equipments
This commit is contained in:
parent
b5d22e57f9
commit
c8ce897013
2 changed files with 24 additions and 45 deletions
|
|
@ -11,7 +11,7 @@ module.exports.player = function(player,serv)
|
||||||
player._client.on("held_item_slot", ({slotId} = {}) => {
|
player._client.on("held_item_slot", ({slotId} = {}) => {
|
||||||
player.heldItemSlot = slotId;
|
player.heldItemSlot = slotId;
|
||||||
player.heldItem = player.inventory.slots[36 + player.heldItemSlot];
|
player.heldItem = player.inventory.slots[36 + player.heldItemSlot];
|
||||||
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId: player.id,
|
entityId: player.id,
|
||||||
slot: 0,
|
slot: 0,
|
||||||
|
|
@ -19,7 +19,7 @@ module.exports.player = function(player,serv)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
player._client.on("window_click", function(clickInfo){
|
player._client.on("window_click", function(clickInfo){
|
||||||
// Do other stuff the inventory doesn't do, eg spawn the dropped item.
|
// Do other stuff the inventory doesn't do, eg spawn the dropped item.
|
||||||
// I've left in stuff that inventory handles, because the cancelling hooks
|
// I've left in stuff that inventory handles, because the cancelling hooks
|
||||||
// might go here (?)
|
// might go here (?)
|
||||||
|
|
@ -141,52 +141,30 @@ module.exports.player = function(player,serv)
|
||||||
|
|
||||||
var newItem = ItemStack.fromNotch(item);
|
var newItem = ItemStack.fromNotch(item);
|
||||||
player.inventory.updateSlot(slot, newItem);
|
player.inventory.updateSlot(slot, newItem);
|
||||||
|
|
||||||
if (slot==5)
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
|
||||||
entityId:player.id,
|
|
||||||
slot:4,
|
|
||||||
item:item
|
|
||||||
});
|
|
||||||
if (slot==6)
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
|
||||||
entityId:player.id,
|
|
||||||
slot:3,
|
|
||||||
item:item
|
|
||||||
});
|
|
||||||
if (slot==7)
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
|
||||||
entityId:player.id,
|
|
||||||
slot:2,
|
|
||||||
item:item
|
|
||||||
});
|
|
||||||
if (slot==8)
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
|
||||||
entityId:player.id,
|
|
||||||
slot:1,
|
|
||||||
item:item
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
player.inventory.on("windowUpdate", function(){
|
player.inventory.on("windowUpdate", function(slot,oldItem,newItem){
|
||||||
|
|
||||||
// Update held item
|
var equipments={
|
||||||
player._writeOthersNearby("entity_equipment",{
|
5:4,
|
||||||
entityId: player.id,
|
6:3,
|
||||||
slot: 0,
|
7:2,
|
||||||
item: ItemStack.toNotch(player.heldItem)
|
8:1
|
||||||
});
|
};
|
||||||
|
equipments[player.heldItemSlot]=0;
|
||||||
// Update slots in inventory
|
if(equipments[slot]!==undefined) {
|
||||||
for(var itemIndex=0;itemIndex<player.inventory.slots.length;itemIndex++) {
|
player._writeOthersNearby("entity_equipment", {
|
||||||
var item = player.inventory.slots[itemIndex];
|
entityId: player.id,
|
||||||
player._client.write("set_slot", {
|
slot: equipments[slot],
|
||||||
windowId: 0,
|
item: ItemStack.toNotch(newItem)
|
||||||
slot: itemIndex,
|
});
|
||||||
item: ItemStack.toNotch(item)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player._client.write("set_slot", {
|
||||||
|
windowId: 0,
|
||||||
|
slot: slot,
|
||||||
|
item: ItemStack.toNotch(newItem)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ module.exports.player=function(player,serv)
|
||||||
player.username=player._client.username;
|
player.username=player._client.username;
|
||||||
serv.players.push(player);
|
serv.players.push(player);
|
||||||
serv.uuidToPlayer[player._client.uuid] = player;
|
serv.uuidToPlayer[player._client.uuid] = player;
|
||||||
|
player.heldItemSlot=36;
|
||||||
player.loadedChunks={};
|
player.loadedChunks={};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue