Here are the changes need to upgrade those mean beds to comfy ones so you don’t end up with a bunch of old beds laying around. It creates an action item when you click on the mean bed that, when clicked on, instantly “upgrades” (i.e. replaces) the mean bed with a comfy one.
This works (with the base alpha 5; haven’t test with post release).
This works (with the base alpha 5; haven’t test with post release), however there are a couple caveats that I would appreciate some help with. The first is that the rotation of the bed is not kept so the comfy one will default back to an unrotated position. The second in that the item information section (lower left of the screen, whatever that is called) will remain as if the mean bed was still selected. Just click on something else and everything is right with the world again, but just a heads up on what to expect.(now fixed, so no longer valid)
Here are the files that you will need to create in your mod.
manifest.json
{
"info": {
"name": The Update Bed Mod"
},
"mixintos": {
"stonehearth/entities/furniture/not_much_of_a_bed/not_much_of_a_bed.json": [
"file(mixintos/not_much_of_a_bed.json)"
]
},
"functions": {
"upgrade_bed" : {
"controller": "file(call_handlers/upgrade_bed_call_handler.lua)",
"endpoint" : "server"
},
"select_new_bed" : {
"controller": "file(call_handlers/upgrade_bed_call_handler.lua)",
"endpoint" : "client"
}
}
}
mixintos/not_much_of_a_bed.json This is their internal name for the mean bed I guess.
{
"components" : {
"stonehearth:commands" : {
"commands" : [
"file(/data/commands/upgrade_bed)",
]
}
}
}
data/commands/upgrade_bed/upgrade_bed.json (note: make sure “myMod” below is replaced with the name of your mod).
{
"type" : "command",
"name": "upgrade_bed",
"tooltip": "Upgrade a bed",
"description": "Turns a straw bed into a comfy one!",
"icon": "/stonehearth/entities/furniture/comfy_bed/comfy_bed.png",
"action": "call",
"function": "myMod:select_new_bed",
"args": [
"{{self}}"
]
}
call_handlers/upgrade_bed_call_handler.luac
-- (9/24/2014 - DrowsySloth) Code to upgrade a mean bed to a comfy one.
-- TODO: Validate that there are no bugs with this (i.e. works in a house, works when bed has an owner, etc).
-- To log use ex: radiant.log.error('server', radiant.entities.get_name(entity) .. ".facing=" .. facing)
local t = class()
function t:upgrade_bed(session, response, entity)
-- Cache the location and rotation of the current bed before we destroy it, so that the new one matches it.
local loc = radiant.entities.get_world_grid_location(entity)
local facing = radiant.entities.get_facing(entity)
-- Remove the mean bed.
radiant.entities.destroy_entity(entity)
-- Create the comfy bed in its place.
local comfyBed = radiant.entities.create_entity('stonehearth:comfy_bed')
radiant.terrain.place_entity(comfyBed, loc, {force_iconic=false})
radiant.entities.turn_to(comfyBed, facing)
return true
end
function t:select_new_bed(session, response, entity)
-- Invoke the server-side method.
_radiant.call('myMod:upgrade_bed', entity)
-- Using nil here to essentially select nothing as there doesn't seem to be a
-- deselect/clear method and I don't have a reference to the comfy bed entity.
stonehearth.selection:select_entity(nil)
return true
end
return t
Hopefully this helps folks.

