tidy and tweak code

This commit is contained in:
TenPlus1 2018-06-09 16:47:38 +01:00
parent aa6dc610cf
commit 6783670154
31 changed files with 249 additions and 252 deletions

View File

@ -1,76 +0,0 @@
local S = farming.intllib
-- Donut (thanks to Bockwurst for making the donut images)
minetest.register_craftitem("farming:donut", {
description = S("Donut"),
inventory_image = "farming_donut.png",
on_use = minetest.item_eat(4),
})
minetest.register_craft({
output = "farming:donut 3",
recipe = {
{"", "group:food_wheat", ""},
{"group:food_wheat", "group:food_sugar", "group:food_wheat"},
{"", "group:food_wheat", ""},
}
})
-- Chocolate Donut
minetest.register_craftitem("farming:donut_chocolate", {
description = S("Chocolate Donut"),
inventory_image = "farming_donut_chocolate.png",
on_use = minetest.item_eat(6),
})
minetest.register_craft({
output = "farming:donut_chocolate",
recipe = {
{'group:food_cocoa'},
{'farming:donut'},
}
})
-- Apple Donut
minetest.register_craftitem("farming:donut_apple", {
description = S("Apple Donut"),
inventory_image = "farming_donut_apple.png",
on_use = minetest.item_eat(6),
})
minetest.register_craft({
output = "farming:donut_apple",
recipe = {
{'default:apple'},
{'farming:donut'},
}
})
-- Porridge Oats
minetest.register_craftitem("farming:porridge", {
description = S("Porridge"),
inventory_image = "farming_porridge.png",
on_use = minetest.item_eat(6, "farming:bowl"),
})
minetest.after(0, function()
local fluid = "bucket:bucket_water"
local fluid_return = "bucket:bucket_water"
if minetest.get_modpath("mobs") and mobs and mobs.mod == "redo" then
fluid = "group:food_milk"
fluid_return = "mobs:bucket_milk"
end
minetest.register_craft({
type = "shapeless",
output = "farming:porridge",
recipe = {
"group:food_barley", "group:food_barley", "group:food_wheat",
"group:food_wheat", "group:food_bowl", fluid
},
replacements = {{fluid_return, "bucket:bucket_empty"}}
})
end)

View File

@ -13,7 +13,6 @@ farming.cucumber = true
farming.corn = true
farming.coffee = true
farming.melon = true
farming.sugar = true
farming.pumpkin = true
farming.cocoa = true
farming.raspberry = true
@ -30,7 +29,6 @@ farming.pepper = true
farming.pineapple = true
farming.peas = true
farming.beetroot = true
farming.donuts = true
-- rarety of crops on map, default is 0.001 (higher number = more crops)
farming.rarety = 0.002

View File

@ -112,3 +112,77 @@ minetest.register_craft({
output = "farming:garlic_bread",
recipe = {"group:food_toast", "group:food_garlic_clove", "group:food_garlic_clove"},
})
--= Donuts (thanks to Bockwurst for making the donut images)
minetest.register_craftitem("farming:donut", {
description = S("Donut"),
inventory_image = "farming_donut.png",
on_use = minetest.item_eat(4),
})
minetest.register_craft({
output = "farming:donut 3",
recipe = {
{"", "group:food_wheat", ""},
{"group:food_wheat", "group:food_sugar", "group:food_wheat"},
{"", "group:food_wheat", ""},
}
})
minetest.register_craftitem("farming:donut_chocolate", {
description = S("Chocolate Donut"),
inventory_image = "farming_donut_chocolate.png",
on_use = minetest.item_eat(6),
})
minetest.register_craft({
output = "farming:donut_chocolate",
recipe = {
{'group:food_cocoa'},
{'farming:donut'},
}
})
minetest.register_craftitem("farming:donut_apple", {
description = S("Apple Donut"),
inventory_image = "farming_donut_apple.png",
on_use = minetest.item_eat(6),
})
minetest.register_craft({
output = "farming:donut_apple",
recipe = {
{'default:apple'},
{'farming:donut'},
}
})
--= Porridge Oats
minetest.register_craftitem("farming:porridge", {
description = S("Porridge"),
inventory_image = "farming_porridge.png",
on_use = minetest.item_eat(6, "farming:bowl"),
})
minetest.after(0, function()
local fluid = "bucket:bucket_water"
local fluid_return = "bucket:bucket_water"
if minetest.get_modpath("mobs") and mobs and mobs.mod == "redo" then
fluid = "group:food_milk"
fluid_return = "mobs:bucket_milk"
end
minetest.register_craft({
type = "shapeless",
output = "farming:porridge",
recipe = {
"group:food_barley", "group:food_barley", "group:food_wheat",
"group:food_wheat", "group:food_bowl", fluid
},
replacements = {{fluid_return, "bucket:bucket_empty"}}
})
end)

View File

@ -1,142 +0,0 @@
-- load support for intllib.
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
-- hoe bomb function
local function hoe_area(pos, player)
-- check for protection
if minetest.is_protected(pos, player:get_player_name()) then
minetest.record_protection_violation(pos, player:get_player_name())
return
end
local r = 5 -- radius
-- remove flora (grass, flowers etc.)
local res = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - 1, z = pos.z - r},
{x = pos.x + r, y = pos.y + 2, z = pos.z + r},
{"group:flora"})
for n = 1, #res do
minetest.swap_node(res[n], {name = "air"})
end
-- replace dirt with tilled soil
res = nil
res = minetest.find_nodes_in_area_under_air(
{x = pos.x - r, y = pos.y - 1, z = pos.z - r},
{x = pos.x + r, y = pos.y + 2, z = pos.z + r},
{"group:soil"})
for n = 1, #res do
minetest.swap_node(res[n], {name = "farming:soil"})
end
end
-- throwable hoe bomb
minetest.register_entity("farming:hoebomb_entity", {
physical = true,
visual = "sprite",
visual_size = {x = 1.0, y = 1.0},
textures = {"farming_hoe_bomb.png"},
collisionbox = {0,0,0,0,0,0},
lastpos = {},
player = "",
on_step = function(self, dtime)
if not self.player then
self.object:remove()
return
end
local pos = self.object:get_pos()
if self.lastpos.x ~= nil then
local vel = self.object:getvelocity()
-- only when potion hits something physical
if vel.x == 0
or vel.y == 0
or vel.z == 0 then
if self.player ~= "" then
-- round up coords to fix glitching through doors
self.lastpos = vector.round(self.lastpos)
hoe_area(self.lastpos, self.player)
end
self.object:remove()
return
end
end
self.lastpos = pos
end
})
-- actual throwing function
local function throw_potion(itemstack, player)
local playerpos = player:get_pos()
local obj = minetest.add_entity({
x = playerpos.x,
y = playerpos.y + 1.5,
z = playerpos.z
}, "farming:hoebomb_entity")
local dir = player:get_look_dir()
local velocity = 20
obj:setvelocity({
x = dir.x * velocity,
y = dir.y * velocity,
z = dir.z * velocity
})
obj:setacceleration({
x = dir.x * -3,
y = -9.5,
z = dir.z * -3
})
obj:setyaw(player:get_look_yaw() + math.pi)
obj:get_luaentity().player = player
end
-- hoe bomb item
minetest.register_craftitem("farming:hoe_bomb", {
description = S("Hoe Bomb (use or throw on grassy areas to hoe land"),
inventory_image = "farming_hoe_bomb.png",
groups = {flammable = 2, not_in_creative_inventory = 1},
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
hoe_area(pointed_thing.above, user)
else
throw_potion(itemstack, user)
if not farming.is_creative(user:get_player_name()) then
itemstack:take_item()
return itemstack
end
end
end,
})

138
hoes.lua
View File

@ -192,3 +192,141 @@ minetest.override_item("farming:hoe_diamond", {
original_description = "Diamond Hoe",
description = toolranks.create_description("Diamond Hoe")})
end
-- hoe bomb function
local function hoe_area(pos, player)
-- check for protection
if minetest.is_protected(pos, player:get_player_name()) then
minetest.record_protection_violation(pos, player:get_player_name())
return
end
local r = 5 -- radius
-- remove flora (grass, flowers etc.)
local res = minetest.find_nodes_in_area(
{x = pos.x - r, y = pos.y - 1, z = pos.z - r},
{x = pos.x + r, y = pos.y + 2, z = pos.z + r},
{"group:flora"})
for n = 1, #res do
minetest.swap_node(res[n], {name = "air"})
end
-- replace dirt with tilled soil
res = nil
res = minetest.find_nodes_in_area_under_air(
{x = pos.x - r, y = pos.y - 1, z = pos.z - r},
{x = pos.x + r, y = pos.y + 2, z = pos.z + r},
{"group:soil"})
for n = 1, #res do
minetest.swap_node(res[n], {name = "farming:soil"})
end
end
-- throwable hoe bomb
minetest.register_entity("farming:hoebomb_entity", {
physical = true,
visual = "sprite",
visual_size = {x = 1.0, y = 1.0},
textures = {"farming_hoe_bomb.png"},
collisionbox = {0,0,0,0,0,0},
lastpos = {},
player = "",
on_step = function(self, dtime)
if not self.player then
self.object:remove()
return
end
local pos = self.object:get_pos()
if self.lastpos.x ~= nil then
local vel = self.object:getvelocity()
-- only when potion hits something physical
if vel.x == 0
or vel.y == 0
or vel.z == 0 then
if self.player ~= "" then
-- round up coords to fix glitching through doors
self.lastpos = vector.round(self.lastpos)
hoe_area(self.lastpos, self.player)
end
self.object:remove()
return
end
end
self.lastpos = pos
end
})
-- actual throwing function
local function throw_potion(itemstack, player)
local playerpos = player:get_pos()
local obj = minetest.add_entity({
x = playerpos.x,
y = playerpos.y + 1.5,
z = playerpos.z
}, "farming:hoebomb_entity")
local dir = player:get_look_dir()
local velocity = 20
obj:setvelocity({
x = dir.x * velocity,
y = dir.y * velocity,
z = dir.z * velocity
})
obj:setacceleration({
x = dir.x * -3,
y = -9.5,
z = dir.z * -3
})
obj:setyaw(player:get_look_yaw() + math.pi)
obj:get_luaentity().player = player
end
-- hoe bomb item
minetest.register_craftitem("farming:hoe_bomb", {
description = S("Hoe Bomb (use or throw on grassy areas to hoe land"),
inventory_image = "farming_hoe_bomb.png",
groups = {flammable = 2, not_in_creative_inventory = 1},
on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
hoe_area(pointed_thing.above, user)
else
throw_potion(itemstack, user)
if not farming.is_creative(user:get_player_name()) then
itemstack:take_item()
return itemstack
end
end
end,
})

View File

@ -7,7 +7,7 @@
farming = {}
farming.mod = "redo"
farming.version = "20180519"
farming.version = "20180609"
farming.path = minetest.get_modpath("farming")
farming.select = {
type = "fixed",
@ -586,7 +586,6 @@ farming.cucumber = true
farming.corn = true
farming.coffee = true
farming.melon = true
farming.sugar = true
farming.pumpkin = true
farming.cocoa = true
farming.raspberry = true
@ -603,7 +602,6 @@ farming.pepper = true
farming.pineapple = true
farming.peas = true
farming.beetroot = true
farming.donuts = true
farming.rarety = 0.002 -- 0.006
@ -632,37 +630,44 @@ dofile(farming.path.."/grass.lua")
dofile(farming.path.."/utensils.lua")
-- default crops
dofile(farming.path.."/wheat.lua")
dofile(farming.path.."/cotton.lua")
dofile(farming.path.."/crops/wheat.lua")
dofile(farming.path.."/crops/cotton.lua")
-- additional crops and food (if enabled)
if farming.carrot then dofile(farming.path.."/carrot.lua") end
if farming.potato then dofile(farming.path.."/potato.lua") end
if farming.tomato then dofile(farming.path.."/tomato.lua") end
if farming.cucumber then dofile(farming.path.."/cucumber.lua") end
if farming.corn then dofile(farming.path.."/corn.lua") end
if farming.coffee then dofile(farming.path.."/coffee.lua") end
if farming.melon then dofile(farming.path.."/melon.lua") end
if farming.sugar then dofile(farming.path.."/food.lua") end
if farming.pumpkin then dofile(farming.path.."/pumpkin.lua") end
if farming.cocoa then dofile(farming.path.."/cocoa.lua") end
if farming.raspberry then dofile(farming.path.."/raspberry.lua") end
if farming.blueberry then dofile(farming.path.."/blueberry.lua") end
if farming.rhubarb then dofile(farming.path.."/rhubarb.lua") end
if farming.beans then dofile(farming.path.."/beanpole.lua") end
if farming.grapes then dofile(farming.path.."/grapes.lua") end
if farming.barley then dofile(farming.path.."/barley.lua") end
if farming.hemp then dofile(farming.path.."/hemp.lua") end
if farming.garlic then dofile(farming.path.."/garlic.lua") end
if farming.onion then dofile(farming.path.."/onion.lua") end
if farming.pepper then dofile(farming.path.."/pepper.lua") end
if farming.pineapple then dofile(farming.path.."/pineapple.lua") end
if farming.peas then dofile(farming.path.."/pea.lua") end
if farming.beetroot then dofile(farming.path.."/beetroot.lua") end
if farming.chili then dofile(farming.path.."/chili.lua") end
if farming.donuts then dofile(farming.path.."/donut.lua") end
-- helper function
local function ddoo(file, check)
if check then
dofile(farming.path .. "/crops/" .. file)
end
end
-- add additional crops and food (if enabled)
ddoo("carrot.lua", farming.carrot)
ddoo("potato.lua", farming.potato)
ddoo("tomato.lua", farming.tomato)
ddoo("cucumber.lua", farming.cucumber)
ddoo("corn.lua", farming.corn)
ddoo("coffee.lua", farming.coffee)
ddoo("melon.lua", farming.melon)
ddoo("pumpkin.lua", farming.pumpkin)
ddoo("cocoa.lua", farming.cocoa)
ddoo("raspberry.lua", farming.raspberry)
ddoo("blueberry.lua", farming.blueberry)
ddoo("rhubarb.lua", farming.rhubarb)
ddoo("beans.lua", farming.beans)
ddoo("grapes.lua", farming.grapes)
ddoo("barley.lua", farming.barley)
ddoo("hemp.lua", farming.hemp)
ddoo("garlic.lua", farming.garlic)
ddoo("onion.lua", farming.onion)
ddoo("pepper.lua", farming.pepper)
ddoo("pineapple.lua", farming.pineapple)
ddoo("peas.lua", farming.peas)
ddoo("beetroot.lua", farming.beetroot)
ddoo("chili.lua", farming.chili)
dofile(farming.path.."/food.lua")
dofile(farming.path.."/mapgen.lua")
dofile(farming.path.."/compatibility.lua") -- Farming Plus compatibility
dofile(farming.path.."/hoebomb.lua")
dofile(farming.path.."/lucky_block.lua")