mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-21 15:51:51 +00:00
More skeletal code
This commit is contained in:
parent
c1571c1bd3
commit
06eda4e2fc
1 changed files with 36 additions and 18 deletions
|
|
@ -20,50 +20,60 @@ module.exports.player = function(player)
|
||||||
});
|
});
|
||||||
|
|
||||||
player._client.on("window_click", function(clickInfo){
|
player._client.on("window_click", function(clickInfo){
|
||||||
// Let the inventory know of the click
|
// Do other stuff the inventory doesn't do, eg spawn the dropped item.
|
||||||
player.inventory.acceptClick(clickInfo)
|
// I've left in stuff that inventory handles, because the cancelling hooks
|
||||||
|
// might go here (?)
|
||||||
// Do other stuff the inventory doesn't do, eg spawn the dropped item
|
|
||||||
switch(clickInfo.mode){
|
switch(clickInfo.mode){
|
||||||
case 0:
|
case 0:
|
||||||
if(clickInfo.button == 0){
|
if(clickInfo.mouseButton == 0){
|
||||||
// Left mouse click
|
// Left mouse click
|
||||||
|
// Inventory deals with this
|
||||||
}else{
|
}else{
|
||||||
// Right mouse click
|
// Right mouse click
|
||||||
|
// Inventory deals with this
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if(clickInfo.button == 0){
|
if(clickInfo.mouseButton == 0){
|
||||||
// Shift + Left click
|
// Shift + Left click
|
||||||
|
// Inventory deals with this
|
||||||
}else{
|
}else{
|
||||||
// Shift + right click
|
// Shift + right click
|
||||||
|
// Inventory deals with this
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// button 0 -> 8, indication hotbar switching
|
// button 0 -> 8, indication hotbar switching items
|
||||||
|
// (Nothing to do with held_item_slot)
|
||||||
|
// DANGER! crashes because windows.js hasn't implemented it yet.
|
||||||
break
|
break
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// Middle click
|
// Middle click
|
||||||
|
// DANGER! crashes because windows.js hasn't implemented it yet.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if(clickInfo.slot == -999){
|
if(clickInfo.slot == -999){
|
||||||
// Click with nothing outside window
|
// Click with nothing outside window. Do nothing.
|
||||||
}else{
|
}else{
|
||||||
if(clickInfo.button == 0){
|
// I'd love to implement this, but dropped entities are not finished.
|
||||||
|
if(clickInfo.mouseButton == 0){
|
||||||
// Drop one item at slot
|
// Drop one item at slot
|
||||||
|
// Inventory handles removing one
|
||||||
}else{
|
}else{
|
||||||
// Drop full stack at slot
|
// Drop full stack at slot
|
||||||
|
// Inventory handles removing the whole stack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Inventory does not support dragging yet, so not implementing yet.
|
||||||
case 5:
|
case 5:
|
||||||
if(clickInfo.slot == -999){
|
if(clickInfo.slot == -999){
|
||||||
switch(clickInfo.button){
|
switch(clickInfo.mouseButton){
|
||||||
case 0:
|
case 0:
|
||||||
// Start left mouse drag
|
// Start left mouse drag
|
||||||
break;
|
break;
|
||||||
|
|
@ -81,7 +91,7 @@ module.exports.player = function(player)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
switch(clickInfo.button){
|
switch(clickInfo.mouseButton){
|
||||||
case 1:
|
case 1:
|
||||||
// Add slot for left mouse drag
|
// Add slot for left mouse drag
|
||||||
break;
|
break;
|
||||||
|
|
@ -93,10 +103,16 @@ module.exports.player = function(player)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Inventory does not support double click yet, so not implementing yet.
|
||||||
case 6:
|
case 6:
|
||||||
// Double click
|
// Double click
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Let the inventory know of the click.
|
||||||
|
// It's important to let it know of the click later, because it destroys
|
||||||
|
// information we need about the inventory.
|
||||||
|
player.inventory.acceptClick(clickInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
player._client.on("set_creative_slot", ({slot,item} ={}) => {
|
player._client.on("set_creative_slot", ({slot,item} ={}) => {
|
||||||
|
|
@ -108,12 +124,6 @@ module.exports.player = function(player)
|
||||||
var newItem = new ItemStack(item.blockId, item.itemCount, item.metadata)
|
var newItem = new ItemStack(item.blockId, item.itemCount, item.metadata)
|
||||||
player.inventory.updateSlot(slot, newItem)
|
player.inventory.updateSlot(slot, newItem)
|
||||||
|
|
||||||
if (slot==36)
|
|
||||||
player._writeOthersNearby("entity_equipment",{
|
|
||||||
entityId:player.id,
|
|
||||||
slot:0,
|
|
||||||
item:item
|
|
||||||
});
|
|
||||||
if (slot==5)
|
if (slot==5)
|
||||||
player._writeOthersNearby("entity_equipment",{
|
player._writeOthersNearby("entity_equipment",{
|
||||||
entityId:player.id,
|
entityId:player.id,
|
||||||
|
|
@ -144,6 +154,14 @@ module.exports.player = function(player)
|
||||||
player.inventory.on("windowUpdate", function(){
|
player.inventory.on("windowUpdate", function(){
|
||||||
var items = player.inventory.slots
|
var items = player.inventory.slots
|
||||||
|
|
||||||
|
// Update held item
|
||||||
|
player._writeOthersNearby("entity_equipment",{
|
||||||
|
entityId: player.id,
|
||||||
|
slot: 0,
|
||||||
|
item: ItemStack.toNotch(player.heldItem)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update slots in inventory
|
||||||
for(var itemIndex in items){
|
for(var itemIndex in items){
|
||||||
var item = items[itemIndex]
|
var item = items[itemIndex]
|
||||||
player._client.write("set_slot", {
|
player._client.write("set_slot", {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue