Problem with registering hoes

Post Reply
Triandra
New member
Posts: 7
Joined: Mon Mar 02, 2020 18:32

Problem with registering hoes

by Triandra » Post

So, I'm really fond of the RealTest subgame Wuzzy brought to life again and am currently trying to get useful mods working with the game. The last mod I tried to adapt was the farming redo mod by TenPlus. Crops and stuff worked out really well, but I can't get a working hoe. Because metals are different in RT I tried registering the original hoe in farming redo. Well, I get the hoe as an object in the game, but it doesn't work like it should. It's rather digging the dirt. I also tried to make an extra mod only for the hoe, with the exact RT farming code, but it still doesn't work. I realized Farming Redo and Realtest farming are using a very different code to define the hoe function, and I tried both versions, but it still didn't work.
So, the Farming Redo code for hoe functioning is:
Spoiler

function farming.hoe_on_use(itemstack, user, pointed_thing, uses)

local pt = pointed_thing

-- check if pointing at a node
if not pt or pt.type ~= "node" then
return
end

local under = minetest.get_node(pt.under)
local upos = pointed_thing.under

if minetest.is_protected(upos, user:get_player_name()) then
minetest.record_protection_violation(upos, user:get_player_name())
return
end

local p = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
local above = minetest.get_node(p)

-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name]
or not minetest.registered_nodes[above.name] then
return
end

-- check if the node above the pointed thing is air
if above.name ~= "air" then
return
end

-- check if pointing at dirt
if minetest.get_item_group(under.name, "soil") ~= 1 then
return
end

-- turn the node into soil, wear out item and play sound
minetest.set_node(pt.under, {name = "farming:soil"})

minetest.sound_play("default_dig_crumbly", {pos = pt.under, gain = 0.5})

local wear = 65535 / (uses -1)

if farming.is_creative(user:get_player_name()) then
if tr then
wear = 1
else
wear = 0
end
end

if tr then
itemstack = toolranks.new_afteruse(itemstack, user, under, {wear = wear})
else
itemstack:add_wear(wear)
end

return itemstack
end
And the Realtest farming code is:
Spoiler

minetest.register_node(":default:dirt", {
description = "Dirt",
tiles = {"default_dirt.png"},
is_ground_content = true,
groups = {crumbly=3,soil=1},
drop = 'default:dirt',
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.25},
}),
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "farming:hoe" then
minetest.set_node(pos, {name="farming:soil"})
end
end,
})

minetest.register_node(":default:dirt_with_grass", {
description = "Grass",
tiles = {"default_dirt_grass.png",
"default_dirt.png",
"default_dirt_grass.png"},
is_ground_content = true,
groups = {crumbly=3,soil=1},
drop = 'default:dirt',
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.25},
}),
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "farming:hoe" then
minetest.set_node(pos, {name="farming:soil"})
end
end,
})
So, does anyone have an idea what I could do?
The Farming Redo hoes aren't working in RT either, by the way, so changing the crafting recipe wouldn't make a difference, I guess.

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: Problem with registering hoes

by Sokomine » Post

Most likely that's due to the handling of soil having changed. Try to do it like the farming mod from MTG does:

Code: Select all

minetest.override_item("default:dirt", {
        soil = {
                base = "default:dirt",
                dry = "farming:soil",
                wet = "farming:soil_wet"
        }
})
You'll also need the node definitions for farming:soil and farming:soil_wet - or adjust the names so that they fit to the ones in RT. Perhaps it's best to take the entire farming mod from MTG (or just farming redo as such) and adjust the look of the nodes there.
A list of my mods can be found here.

Triandra
New member
Posts: 7
Joined: Mon Mar 02, 2020 18:32

Re: Problem with registering hoes

by Triandra » Post

Sokomine wrote:
Sun May 03, 2020 01:02
Most likely that's due to the handling of soil having changed. Try to do it like the farming mod from MTG does:
Thank you Sokomine, unfortunately it didn't work. I added the code to my version of farming redo, but neither the original RT hoe nor the farming redo hoes work. I have absolutely no idea what's going on there. The only other alternative I see is renaming the farming redo mod and everything in it, so it doesn't overwrite the RT farming mod and only adds crops and stuff... Maybe that'll work out.
I'm still very grateful for your response, it sounded promising.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 8 guests