Rotton Meat: craftitem ABM?

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

Rotton Meat: craftitem ABM?

by wulfsdad » Wed Dec 12, 2012 02:35

I'm working on a mod to extend PilzAdam's Simple Mobs.
One of the things I wanted to include is the possibility of meat retrieved from animals that remains uncooked to turn into rotten meat.

I'm wondering if there is a function or functions that I can use to periodically check chests, player inventory, and the environment for raw meat and modify it. I tried using register_abm but it didn't work. I don't think it works with craftitems.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
--Meat Rotting--
minetest.register_craftitem("my_mobs:meat_rotten", {
    description = "Rotten Meat",
    image = "meat_rotten.png",
    on_use = minetest.item_eat(-6),
    groups = { meat=1, eatable=1 },
})

minetest.register_craft({
    type = "cooking",
    output = "scorched_stuff",
    recipe = "my_mobs:meat_rotten",
    cooktime = 5,
})

-- minetest.register_abm(
--     {nodenames = {"mobs:meat"},
--     interval = 10,
--     chance = 1,
--     action = function(pos)
--         minetest.env:add_node(pos, {name="my_mobs:meat_rotten"})
--     end,
-- })
Last edited by wulfsdad on Wed Dec 12, 2012 02:35, edited 1 time in total.
 

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

by wulfsdad » Wed Dec 12, 2012 02:58

I tried this too:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_abm({
    nodenames = { "mobs:meat" },
    interval = 1,
    chance = 1, -- TESTING adjust once it works
    action = function(pos, node, active_object_count, active_object_count_wider)
        minetest.env:remove_node(pos)
        minetest.env:add_node(pos,{name="my_mobs:meat_rotten"})
    end
})
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Dec 12, 2012 15:44

ABMs only work with nodes that are placed in the world. You maybe can implement this with register_on_step() (see lua-api.txt).
 

User avatar
LorenzoVulcan
Member
 
Posts: 437
Joined: Mon Mar 12, 2012 06:46

by LorenzoVulcan » Wed Dec 12, 2012 15:45

You can use a timer on minetest.after(time,func) but that's not so perfomable.
Developer of the BlockForge 2# Project!
Official thread: http://minetest.net/forum/viewtopic.php?pid=54290#p54290
 

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

by wulfsdad » Thu Dec 13, 2012 07:15

Sweet! Thanks for the replies. I used minetest.register_globalstep( function(dtime) ) and so far have got it working for meat in the player's inventory.
I'm not sure how items that are laying around the environment are handled. I'm thinking I can get them in a list as an InvRef with minetest.get_inventory(location) but I'm not sure what to pass as the location. I see an example of {type="detached", name="creative"}which looks promising, but I'm not sure what options I have for passing as the parameters. I'm going to experiment with it tomorrow if I can't find any more documentation.
Also, for locating all the containers (chests and such) is there a function or constant that will give me the size of the map that I can use for figuring out the minp and maxp parameters for find_nodes_in_area(minp, maxp, nodenames)?
Thanks again!

Here's what I've got so far:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local rotting_timer = 0
minetest.register_globalstep( function(dtime)
    rotting_timer = rotting_timer + dtime
    if rotting_timer >= 720 then
   
        --Rot Droped Meat
        --If it's in the watter (due to drowned cattle) then raise the chance of it rotting
--         local litter = minetest.get_inventory({type="detached", name="creative"})
--         if not litter:is_empty("main") then
--
--         end

        --Rot Harvested Meat
        for _,player in ipairs(minetest.get_connected_players()) do
            local who = player:get_player_name()
            local stuff = player:get_inventory()
            for i=1,32 do -- TODO: MAKE GENERIC
                 local item = stuff:get_stack("main", i)
                 if item:get_name() == "mobs:meat_raw" then
--                    for j=1,item:get_count() do --TODO: Rot partial stacks
                         if math.random(1,100) > 66 then -- about 1/3 chance
                            item:replace({name = "my_mobs:meat_rotten", count = item:get_count(), wear=0, metadata=""})
                            stuff:set_stack("main", i, item)
                            minetest.chat_send_player(who, "Something in your inventory is starting to smell bad!") -- TODO: Change or have multiple strings to choose from randomly
                         end -- if by random chance
--                    end -- for each item in stack [j]
                 end -- if is meat
             end -- for each (32) inventory slot [i]
        end -- for each player
       
        --Rot Stored Meat [Except in refridgerator with addon]
--WORKING:
--         find_nodes_in_area(minp, maxp, nodenames) -> list of positions
--         ^ nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
--                    minetest.env:get_nodemeta(pos):get_inventory() -> InvRef

        rotting_timer = 0 --reset the timer
    end -- timer
end)
Last edited by wulfsdad on Thu Dec 13, 2012 09:55, edited 1 time in total.
 

User avatar
Aqua
Member
 
Posts: 641
Joined: Wed Aug 22, 2012 09:11

by Aqua » Thu Dec 13, 2012 09:14

Wicked! Thanks for this code, can I use this in my mod?
Hi there ^.~
 

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

by wulfsdad » Thu Dec 13, 2012 09:54

Sure, WTFPL.


....

Aha! Never mind about the map size, I'll just use an ABM for the chests. Duh!
Last edited by wulfsdad on Thu Dec 13, 2012 10:38, edited 1 time in total.
 

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

by wulfsdad » Thu Dec 13, 2012 14:29

I don't have permission to post in Mod Releases, so I guess I'll just post links here:


This MOD provides additional mobs to extend upon PilzAdam's Simple Mobs.
http://minetest.net/forum/viewtopic.php?id=3063

It Includes:
Animals:
Cow (and milk -- retrieved using right-click with a bucket or vessel),
Rabbit
Overcooking and using the resulting burnt stuff to make dye,
Meat spoilage if it remains uncooked over tiime

Raw meet can be preserved through "cheating" or using a refridgerator provided by VanessaE's Home Decor Mod
http://minetest.net/forum/viewtopic.php?id=2041

KNOWN BUGS:
If you drink milk from a stack of vessels, you will not recieve the empty vessel.

Download Version 0.0 here:
If you don't want to use the homedecor mod then http://www.freewebs.com/moonsdad/bin/mt_mod/my_mobs_0.0-basic.zip
If you do want to use it then http://www.freewebs.com/moonsdad/bin/mt_mod/my_mobs_0.0-full.zip
 

Doc
Member
 
Posts: 75
Joined: Sun Nov 04, 2012 00:21

by Doc » Thu Dec 13, 2012 21:38

wulfsdad wrote:I don't have permission to post in Mod Releases, so I guess I'll just post links here

You post your mod in modding general then go to the Topic Move Requests thread and post a link to your thread, and ask for your mod to be moved. Be sure to make it in this format:
[mod]Mod name[modname]

[mod] is either that, or [modpack], depending on the mod/modpack. Mod name is obvious... [modname] is the name that the mod folder has to be in the mods/minetest folder (ie my farming mod is [docfarming]).
 

wulfsdad
Member
 
Posts: 43
Joined: Tue Dec 04, 2012 10:38

by wulfsdad » Fri Dec 14, 2012 02:53

Doc wrote:You post your mod in modding general then go to the Topic Move Requests thread and post a link to your thread, and ask for your mod to be moved.


Ok, thanks. I'll do that with the next update.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 22 guests

cron