From 00f1816bdfd40d6f17849a5783a3b2ca588222b5 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 23 Jun 2017 16:29:09 +0200 Subject: [PATCH] Make all items overwritable --- 1_items_default.lua | 656 ++++++++++++++++++++++++-------------------- 2_throwing.lua | 478 ++++++++++++++++---------------- 2 files changed, 600 insertions(+), 534 deletions(-) diff --git a/1_items_default.lua b/1_items_default.lua index d504f46..4717ad4 100644 --- a/1_items_default.lua +++ b/1_items_default.lua @@ -7,11 +7,20 @@ --dofile(minetest.get_modpath("mobs").."/api.lua") --THIS IS THE MASTER ITEM LIST TO USE WITH DEFAULT -local function c(id) - return string.sub(mobs_mc.items[id], 1, 8) == "mobs_mc:" +-- This function checks if the item ID has been overwritten and returns true if it is unchanged +local c +if minetest.get_modpath("mobs_mc_gameconfig") and mobs_mc.override and mobs_mc.override.items then + c = function(id) + return mobs_mc.overrmobs_mc.override.items[id] == nil + end +else + -- No items are overwritten, so always return true + c = function(id) + return true + end end ---blaze +-- Blaze if c("blaze_rod") then minetest.register_craftitem("mobs_mc:blaze_rod", { description = "Blaze Rod", @@ -19,6 +28,24 @@ if c("blaze_rod") then wield_image = "mcl_mobitems_blaze_rod.png", inventory_image = "mcl_mobitems_blaze_rod.png", }) + + -- Make blaze rod furnace-burnable. 1.5 times the burn time of a coal lump + local coalcraft, burntime + if minetest.get_modpath("default") then + coalcraft = minetest.get_craft_result({method="fuel", width=1, items={"default:coal_lump"}}) + end + if coalcraft then + burntime = math.floor(coalcraft.time * 1.5) + end + if burntime == nil or burntime == 0 then + burntime = 60 + end + + minetest.register_craft({ + type = "fuel", + burntime = burntime, + recipe = "mobs_mc:blaze_rod", + }) end if c("blaze_powder") then @@ -37,25 +64,7 @@ if c("blaze_rod") and c("blaze_powder") then }) end --- Make blaze rod furnace-burnable. 1.5 times the burn time of a coal lump -local coalcraft, burntime -if minetest.get_modpath("default") then - coalcraft = minetest.get_craft_result({method="fuel", width=1, items={"default:coal_lump"}}) -end -if coalcraft then - burntime = math.floor(coalcraft.time * 1.5) -end -if burntime == nil or burntime == 0 then - burntime = 60 -end - -minetest.register_craft({ - type = "fuel", - burntime = burntime, - recipe = "mobs_mc:blaze_rod", -}) - --- chicken +-- Chicken if c("chicken_raw") then minetest.register_craftitem("mobs_mc:chicken_raw", { description = "Raw Chicken", @@ -90,202 +99,231 @@ if c("feather") then }) end ---cows - --- Craftitems --- beef -minetest.register_craftitem("mobs_mc:beef_raw", { - description = "Raw Beef", - inventory_image = "mcl_mobitems_beef_raw.png", - groups = { food = 2, eatable = 3 }, - on_use = minetest.item_eat(3), -}) - -minetest.register_craftitem("mobs_mc:beef_cooked", { - description = "Steak", - inventory_image = "mcl_mobitems_beef_cooked.png", - groups = { food = 2, eatable = 8 }, - on_use = minetest.item_eat(8), -}) - -minetest.register_craft({ - type = "cooking", - output = "mobs_mc:beef_cooked", - recipe = "mobs_mc:beef_raw", - cooktime = 5, -}) - --- Bowl and mushroom stew -minetest.register_craftitem("mobs_mc:bowl", { - description = "Bowl", - inventory_image = "mcl_core_bowl.png", -}) - -minetest.register_craft({ - output = "mobs_mc:bowl", - recipe = { - { "group:wood", "", "group:wood" }, - { "", "group:wood", "", }, - } -}) - -minetest.register_craft({ - type = "fuel", - recipe = "mobs_mc:bowl", - burntime = 5, -}) - -minetest.register_craftitem("mobs_mc:mushroom_stew", { - description = "Mushroom Stew", - inventory_image = "farming_mushroom_stew.png", - groups = { food = 3, eatable = 6 }, - on_use = minetest.item_eat(6, "mobs_mc:bowl"), - stack_max = 1, -}) - --- milk -minetest.register_craftitem("mobs_mc:milk_bucket", { - description = "Milk", - inventory_image = "mobs_bucket_milk.png", - groups = { food = 3, eatable = 1 }, - on_use = minetest.item_eat(1, "bucket:bucket_empty"), - stack_max = 1, -}) - -local dragon_egg_sounds -if minetest.get_modpath("default") then - dragon_egg_sounds = default.node_sound_stone_defaults() +-- Cow and mooshroom +if c("beef_raw") then + minetest.register_craftitem("mobs_mc:beef_raw", { + description = "Raw Beef", + inventory_image = "mcl_mobitems_beef_raw.png", + groups = { food = 2, eatable = 3 }, + on_use = minetest.item_eat(3), + }) end ---ender dragon -minetest.register_node("mobs_mc:dragon_egg", { - description = "Dragon Egg", - tiles = { - "mcl_end_dragon_egg.png", - "mcl_end_dragon_egg.png", - "mcl_end_dragon_egg.png", - "mcl_end_dragon_egg.png", - "mcl_end_dragon_egg.png", - "mcl_end_dragon_egg.png", - }, - drawtype = "nodebox", - is_ground_content = false, - paramtype = "light", - light_source = 1, - node_box = { - type = "fixed", - fixed = { - {-0.375, -0.5, -0.375, 0.375, -0.4375, 0.375}, - {-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, - {-0.4375, -0.1875, -0.4375, 0.4375, 0, 0.4375}, - {-0.375, 0, -0.375, 0.375, 0.125, 0.375}, - {-0.3125, 0.125, -0.3125, 0.3125, 0.25, 0.3125}, - {-0.25, 0.25, -0.25, 0.25, 0.3125, 0.25}, - {-0.1875, 0.3125, -0.1875, 0.1875, 0.375, 0.1875}, - {-0.125, 0.375, -0.125, 0.125, 0.4375, 0.125}, - {-0.0625, 0.4375, -0.0625, 0.0625, 0.5, 0.0625}, +if c("beef_cooked") then + minetest.register_craftitem("mobs_mc:beef_cooked", { + description = "Steak", + inventory_image = "mcl_mobitems_beef_cooked.png", + groups = { food = 2, eatable = 8 }, + on_use = minetest.item_eat(8), + }) +end + +if c("beef_raw") and c("beef_cooked") then + minetest.register_craft({ + type = "cooking", + output = "mobs_mc:beef_cooked", + recipe = "mobs_mc:beef_raw", + cooktime = 5, + }) +end + + +if c("milk_bucket") then + -- milk + minetest.register_craftitem("mobs_mc:milk_bucket", { + description = "Milk", + inventory_image = "mobs_bucket_milk.png", + groups = { food = 3, eatable = 1 }, + on_use = minetest.item_eat(1, "bucket:bucket_empty"), + stack_max = 1, + }) +end + +if c("bowl") then + minetest.register_craftitem("mobs_mc:bowl", { + description = "Bowl", + inventory_image = "mcl_core_bowl.png", + }) + + minetest.register_craft({ + output = "mobs_mc:bowl", + recipe = { + { "group:wood", "", "group:wood" }, + { "", "group:wood", "", }, } - }, - selection_box = { - type = "regular", - }, - groups = {snappy = 1, falling_node = 1, deco_block = 1, not_in_creative_inventory = 1, dig_by_piston = 1 }, - sounds = dragon_egg_sounds, - -- TODO: Make dragon egg teleport on punching -}) + }) ---enderman -minetest.register_craftitem("mobs_mc:ender_eye", { - description = "Ender Eye", + minetest.register_craft({ + type = "fuel", + recipe = "mobs_mc:bowl", + burntime = 5, + }) +end - inventory_image = "mcl_end_ender_eye.png", - groups = { craftitem = 1 }, -}) +if c("mushroom_stew") then + minetest.register_craftitem("mobs_mc:mushroom_stew", { + description = "Mushroom Stew", + inventory_image = "farming_mushroom_stew.png", + groups = { food = 3, eatable = 6 }, + on_use = minetest.item_eat(6, "mobs_mc:bowl"), + stack_max = 1, + }) +end -minetest.register_craft({ - type = "shapeless", - output = 'mobs_mc:ender_eye', - recipe = { 'mobs_mc:blaze_powder', 'mobs_mc:blaze_rod'}, -}) +-- Ender dragon +if c("dragon_egg") then + + local dragon_egg_sounds + if minetest.get_modpath("default") then + dragon_egg_sounds = default.node_sound_stone_defaults() + end + + --ender dragon + minetest.register_node("mobs_mc:dragon_egg", { + description = "Dragon Egg", + tiles = { + "mcl_end_dragon_egg.png", + "mcl_end_dragon_egg.png", + "mcl_end_dragon_egg.png", + "mcl_end_dragon_egg.png", + "mcl_end_dragon_egg.png", + "mcl_end_dragon_egg.png", + }, + drawtype = "nodebox", + is_ground_content = false, + paramtype = "light", + light_source = 1, + node_box = { + type = "fixed", + fixed = { + {-0.375, -0.5, -0.375, 0.375, -0.4375, 0.375}, + {-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, + {-0.4375, -0.1875, -0.4375, 0.4375, 0, 0.4375}, + {-0.375, 0, -0.375, 0.375, 0.125, 0.375}, + {-0.3125, 0.125, -0.3125, 0.3125, 0.25, 0.3125}, + {-0.25, 0.25, -0.25, 0.25, 0.3125, 0.25}, + {-0.1875, 0.3125, -0.1875, 0.1875, 0.375, 0.1875}, + {-0.125, 0.375, -0.125, 0.125, 0.4375, 0.125}, + {-0.0625, 0.4375, -0.0625, 0.0625, 0.5, 0.0625}, + } + }, + selection_box = { + type = "regular", + }, + groups = {snappy = 1, falling_node = 1, deco_block = 1, not_in_creative_inventory = 1, dig_by_piston = 1 }, + sounds = dragon_egg_sounds, + -- TODO: Make dragon egg teleport on punching + }) +end + +-- Enderman +if c("ender_eye") then + minetest.register_craftitem("mobs_mc:ender_eye", { + description = "Ender Eye", + + inventory_image = "mcl_end_ender_eye.png", + groups = { craftitem = 1 }, + }) +end + +if c("ender_eye") and c("blaze_powder") and c("blaze_rod") then + minetest.register_craft({ + type = "shapeless", + output = 'mobs_mc:ender_eye', + recipe = { 'mobs_mc:blaze_powder', 'mobs_mc:blaze_rod'}, + }) +end -- Ghast -minetest.register_craftitem("mobs_mc:ghast_tear", { - description = "Ghast Tear", - _doc_items_longdesc = "A ghast tear is an item used in potion brewing. It is dropped from dead ghasts.", - wield_image = "mcl_mobitems_ghast_tear.png", - inventory_image = "mcl_mobitems_ghast_tear.png", - groups = { brewitem = 1 }, -}) - +if c("ghast_tear") then + minetest.register_craftitem("mobs_mc:ghast_tear", { + description = "Ghast Tear", + _doc_items_longdesc = "A ghast tear is an item used in potion brewing. It is dropped from dead ghasts.", + wield_image = "mcl_mobitems_ghast_tear.png", + inventory_image = "mcl_mobitems_ghast_tear.png", + groups = { brewitem = 1 }, + }) +end -- Saddle +if c("saddle") then + minetest.register_craftitem("mobs_mc:saddle", { + description = "Saddle", + inventory_image = "mcl_mobitems_saddle.png", + stack_max = 1, + }) -minetest.register_craftitem("mobs_mc:saddle", { - description = "Saddle", - inventory_image = "mcl_mobitems_saddle.png", - stack_max = 1, -}) +if c("saddle") and c("lether") and c("string") and c("iron_ingot") then + minetest.register_craft({ + output = "mobs_mc:saddle", + recipe = { + {"mobs:leather", "mobs:leather", "mobs:leather"}, + {"farming:string", "", "farming:string"}, + {"default:steel_ingot", "", "default:steel_ingot"} + }, + }) +end -minetest.register_craft({ - output = "mobs_mc:saddle", - recipe = { - {"mobs:leather", "mobs:leather", "mobs:leather"}, - {"farming:string", "", "farming:string"}, - {"default:steel_ingot", "", "default:steel_ingot"} - }, -}) +-- Pig +if c("porkchop_raw") then + minetest.register_craftitem("mobs_mc:porkchop_raw", { + description = "Raw Porkchop", + inventory_image = "mcl_mobitems_porkchop_raw.png", + groups = { food = 2, eatable = 3 }, + on_use = minetest.item_eat(3), + }) +end +if c("porkchop_cooked") then + minetest.register_craftitem("mobs_mc:porkchop_cooked", { + description = "Cooked Porkchop", + inventory_image = "mcl_mobitems_porkchop_cooked.png", + groups = { food = 2, eatable = 8 }, + on_use = minetest.item_eat(8), + }) +end ---pig +if c("porkchop_raw") and c("porkchop_cooked") then + minetest.register_craft({ + type = "cooking", + output = "mobs_mc:porkchop_raw", + recipe = "mobs_mc:porkchop_cooked", + cooktime = 5, + }) +end --- pork -minetest.register_craftitem("mobs_mc:porkchop_raw", { - description = "Raw Porkchop", - inventory_image = "mcl_mobitems_porkchop_raw.png", - groups = { food = 2, eatable = 3 }, - on_use = minetest.item_eat(3), -}) +if c("carrot_on_a_stick") then + minetest.register_tool("mobs_mc:carrot_on_a_stick", { + description = "Carrot on a Stick", + wield_image = "mcl_mobitems_carrot_on_a_stick.png", + inventory_image = "mcl_mobitems_carrot_on_a_stick.png", + sounds = { breaks = "default_tool_breaks" }, + }) +end -minetest.register_craftitem("mobs_mc:porkchop_cooked", { - description = "Cooked Porkchop", - inventory_image = "mcl_mobitems_porkchop_cooked.png", - groups = { food = 2, eatable = 8 }, - on_use = minetest.item_eat(8), -}) +-- Poor-man's recipes for carrot on a stick +if c("carrot_on_a_stick") and c("stick") and c("string") and minetest.get_modpath("farming") then + minetest.register_craft({ + output = "mobs_mc:carrot_on_a_stick", + recipe = { + {"", "", "farming:string" }, + {"", "group:stick", "farming:string" }, + {"group:stick", "", "farming:bread" }, + } + }) -minetest.register_craft({ - type = "cooking", - output = "mobs_mc:porkchop_raw", - recipe = "mobs_mc:porkchop_cooked", - cooktime = 5, -}) +-- FIXME: Identify correct farming mod (check if it includes the carrot item) + minetest.register_craft({ + output = "mobs_mc:carrot_on_a_stick", + recipe = { + {"", "", "farming:string" }, + {"", "group:stick", "farming:string" }, + {"group:stick", "", "farming:carrot" }, + } + }) +end -minetest.register_tool("mobs_mc:carrot_on_a_stick", { - description = "Carrot on a Stick", - wield_image = "mcl_mobitems_carrot_on_a_stick.png", - inventory_image = "mcl_mobitems_carrot_on_a_stick.png", - sounds = { breaks = "default_tool_breaks" }, -}) - -minetest.register_craft({ - output = "mobs_mc:carrot_on_a_stick", - recipe = { - {"", "", "farming:string" }, - {"", "group:stick", "farming:string" }, - {"group:stick", "", "farming:bread" }, - } -}) - -minetest.register_craft({ - output = "mobs_mc:carrot_on_a_stick", - recipe = { - {"", "", "farming:string" }, - {"", "group:stick", "farming:string" }, - {"group:stick", "", "farming:carrot" }, - } -}) - -if minetest.get_modpath("fishing") then +if c("carrot_on_a_stick") and c("stick") and c("string") and minetest.get_modpath("fishing") and minetest.get_modpath("farming") then minetest.register_craft({ type = "shapeless", output = "mobs_mc:carrot_on_a_stick", @@ -293,117 +331,131 @@ if minetest.get_modpath("fishing") then }) end +-- Rabbit +if c("rabbit_raw") then + minetest.register_craftitem("mobs_mc:rabbit_raw", { + description = "Raw Rabbit", + inventory_image = "mcl_mobitems_rabbit_raw.png", + groups = { food = 2, eatable = 3 }, + on_use = minetest.item_eat(3), + }) +end ---Rabbit +if c("rabbit_cooked") then + minetest.register_craftitem("mobs_mc:rabbit_cooked", { + description = "Cooked Rabbit", + inventory_image = "mcl_mobitems_rabbit_cooked.png", + groups = { food = 2, eatable = 5 }, + on_use = minetest.item_eat(5), + }) +end --- Items -minetest.register_craftitem("mobs_mc:rabbit_raw", { - description = "Raw Rabbit", - inventory_image = "mcl_mobitems_rabbit_raw.png", - groups = { food = 2, eatable = 3 }, - on_use = minetest.item_eat(3), -}) +if c("rabbit_raw") and c("rabbit_cooked") then + minetest.register_craft({ + type = "cooking", + output = "mobs_mc:rabbit_cooked", + recipe = "mobs_mc:rabbit_raw", + cooktime = 5, + }) +end -minetest.register_craftitem("mobs_mc:rabbit_cooked", { - description = "Cooked Rabbit", - inventory_image = "mcl_mobitems_rabbit_cooked.png", - groups = { food = 2, eatable = 5 }, - on_use = minetest.item_eat(5), -}) +if c("rabbit_hide") then + minetest.register_craftitem("mobs_mc:rabbit_hide", { + description = "Rabbit Hide", + inventory_image = "mcl_mobitems_rabbit_hide.png" + }) +end -minetest.register_craft({ - type = "cooking", - output = "mobs_mc:rabbit_cooked", - recipe = "mobs_mc:rabbit_raw", - cooktime = 5, -}) +if c("leather") and c("rabbit_hide") then + minetest.register_craft({ + output = "mobs:leather", + recipe = { + { "mobs_mc:rabbit_hide", "mobs_mc:rabbit_hide" }, + { "mobs_mc:rabbit_hide", "mobs_mc:rabbit_hide" }, + } + }) +end -minetest.register_craftitem("mobs_mc:rabbit_hide", { - description = "Rabbit Hide", - inventory_image = "mcl_mobitems_rabbit_hide.png" -}) +-- Sheep +if c("mutton_raw") then + minetest.register_craftitem("mobs_mc:mutton_raw", { + description = "Raw Mutton", + inventory_image = "mcl_mobitems_mutton_raw.png", + groups = { food = 2, eatable = 4 }, + on_use = minetest.item_eat(4), + }) +end -minetest.register_craft({ - output = "mobs:leather", - recipe = { - { "mobs_mc:rabbit_hide", "mobs_mc:rabbit_hide" }, - { "mobs_mc:rabbit_hide", "mobs_mc:rabbit_hide" }, - } -}) +if c("mutton_cooked") then + minetest.register_craftitem("mobs_mc:mutton_cooked", { + description = "Cooked Mutton", + inventory_image = "mcl_mobitems_mutton_cooked.png", + groups = { food = 2, eatable = 8 }, + on_use = minetest.item_eat(8), + }) +end ---sheep +if c("mutton_raw") and c("mutton_cooked") then + minetest.register_craft({ + type = "cooking", + output = "mobs_mc:mutton_cooked", + recipe = "mobs_mc:mutton_raw", + cooktime = 5, + }) +end ---mutton -minetest.register_craftitem("mobs_mc:mutton_raw", { - description = "Raw Mutton", - inventory_image = "mcl_mobitems_mutton_raw.png", - groups = { food = 2, eatable = 4 }, - on_use = minetest.item_eat(4), -}) +-- Shulker +if c("shulker_shell") then + minetest.register_craftitem("mobs_mc:shulker_shell", { + description = "Shulker Shell", + inventory_image = "mcl_mobitems_shulker_shell.png", + groups = { craftitem = 1 }, + }) +end -minetest.register_craftitem("mobs_mc:mutton_cooked", { - description = "Cooked Mutton", - inventory_image = "mcl_mobitems_mutton_cooked.png", - groups = { food = 2, eatable = 8 }, - on_use = minetest.item_eat(8), -}) +-- Magma cube +if c("magma_cream") then + minetest.register_craftitem("mobs_mc:magma_cream", { + description = "Magma Cream", + _doc_items_longdesc = "Magma cream is a crafting component.", + wield_image = "mcl_mobitems_magma_cream.png", + inventory_image = "mcl_mobitems_magma_cream.png", + groups = { brewitem = 1 }, + }) +end -minetest.register_craft({ - type = "cooking", - output = "mobs_mc:mutton_cooked", - recipe = "mobs_mc:mutton_raw", - cooktime = 5, -}) +-- Spider +if c("spider_eye") then + minetest.register_craftitem("mobs_mc:spider_eye", { + description = "Spider Eye", + _doc_items_longdesc = "Spider eyes are used mainly in crafting and brewing. If you're really desperate, you can eat a spider eye for 2 hunger points, but it will poison you.", + inventory_image = "mcl_mobitems_spider_eye.png", + wield_image = "mcl_mobitems_spider_eye.png", + -- Simplified poisonous food + groups = { food = 2, eatable = -2 }, + on_use = minetest.item_eat(-2), + }) +end +-- Evoker +if c("totem") then + minetest.register_craftitem("mobs_mc:totem", { + description = "Totem", + wield_image = "mcl_mobitems_totem.png", + inventory_image = "mcl_mobitems_totem.png", + groups = {fleshy=3,dig_immediate=3,flammable=2}, + stack_max =1, + on_use = minetest.item_eat(20), + }) +end ---shulker - -minetest.register_craftitem("mobs_mc:shulker_shell", { - description = "Shulker Shell", - inventory_image = "mcl_mobitems_shulker_shell.png", - groups = { craftitem = 1 }, -}) - ---magma cube -minetest.register_craftitem("mobs_mc:magma_cream", { - description = "Magma Cream", - _doc_items_longdesc = "Magma cream is a crafting component.", - wield_image = "mcl_mobitems_magma_cream.png", - inventory_image = "mcl_mobitems_magma_cream.png", - groups = { brewitem = 1 }, -}) - - ---spider - -minetest.register_craftitem("mobs_mc:spider_eye", { - description = "Spider Eye", - _doc_items_longdesc = "Spider eyes are used mainly in crafting and brewing. If you're really desperate, you can eat a spider eye for 2 hunger points, but it will poison you.", - inventory_image = "mcl_mobitems_spider_eye.png", - wield_image = "mcl_mobitems_spider_eye.png", - -- Simplified poisonous food - groups = { food = 2, eatable = -2 }, - on_use = minetest.item_eat(-2), -}) - ---vex -minetest.register_craftitem("mobs_mc:totem", { - description = "Totem", - wield_image = "mcl_mobitems_totem.png", - inventory_image = "mcl_mobitems_totem.png", - groups = {fleshy=3,dig_immediate=3,flammable=2}, - stack_max =1, - on_use = minetest.item_eat(20), -}) - ---zombie - --- meat rotted -minetest.register_craftitem("mobs_mc:rotten_flesh", { - description = "Rotten Flesh", - inventory_image = "mobs_rotten_flesh.png", - -- Simplified poisonous food - groups = { food = 2, eatable = -4 }, - on_use = minetest.item_eat(-4), -}) - +-- Rotten flesh +if c("rotten_flesh") then + minetest.register_craftitem("mobs_mc:rotten_flesh", { + description = "Rotten Flesh", + inventory_image = "mobs_rotten_flesh.png", + -- Simplified poisonous food + groups = { food = 2, eatable = -4 }, + on_use = minetest.item_eat(-4), + }) +end diff --git a/2_throwing.lua b/2_throwing.lua index 2bec13b..e0cdcb4 100644 --- a/2_throwing.lua +++ b/2_throwing.lua @@ -6,73 +6,92 @@ --maikerumines throwing code --arrow (weapon) -minetest.register_craftitem("mobs_mc:arrow", { - description = "Arrow", - inventory_image = "throwing_arrow_2.png", -}) -minetest.register_node("mobs_mc:arrow_box", { - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - -- Shaft - {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17}, - --Spitze - {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17}, - {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17}, - --Federn - {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17}, - {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17}, - {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17}, - {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17}, +local c +if minetest.get_modpath("mobs_mc_gameconfig") and mobs_mc.override and mobs_mc.override.items then + c = function(id) + return mobs_mc.override.items[id] == nil + end +else + -- No items are overwritten, so always return true + c = function(id) + return true + end +end +if c("arrow") then + minetest.register_craftitem("mobs_mc:arrow", { + description = "Arrow", + inventory_image = "throwing_arrow_2.png", + }) - {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17}, - {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17}, - {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17}, - {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17}, - } - }, - tiles = {"throwing_arrow.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"}, - groups = {not_in_creative_inventory=1}, -}) + minetest.register_node("mobs_mc:arrow_box", { + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + -- Shaft + {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17}, + --Spitze + {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17}, + {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17}, + --Federn + {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17}, + {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17}, + {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17}, + {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17}, + {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17}, + {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17}, + {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17}, + {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17}, + } + }, + tiles = {"throwing_arrow.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"}, + groups = {not_in_creative_inventory=1}, + }) + local THROWING_ARROW_ENTITY={ + physical = false, + timer=0, + visual = "wielditem", + visual_size = {x=0.1, y=0.1}, + textures = {"mobs_mc:arrow_box"}, + velocity = 10, + lastpos={}, + collisionbox = {0,0,0,0,0,0}, + } -local THROWING_ARROW_ENTITY={ - physical = false, - timer=0, - visual = "wielditem", - visual_size = {x=0.1, y=0.1}, - textures = {"mobs_mc:arrow_box"}, - velocity = 10, - lastpos={}, - collisionbox = {0,0,0,0,0,0}, -} + --ARROW CODE + THROWING_ARROW_ENTITY.on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + local node = minetest.get_node(pos) + minetest.add_particle({ + pos = pos, + vel = {x=0, y=0, z=0}, + acc = {x=0, y=0, z=0}, + expirationtime = .3, + size = 1, + collisiondetection = false, + vertical = false, + texture = "mobs_mc_arrow_particle.png", + }) ---ARROW CODE -THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - local node = minetest.get_node(pos) - -minetest.add_particle({ - pos = pos, - vel = {x=0, y=0, z=0}, - acc = {x=0, y=0, z=0}, - expirationtime = .3, - size = 1, - collisiondetection = false, - vertical = false, - texture = "mobs_mc_arrow_particle.png", -}) - - if self.timer>0.2 then - local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) - for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "mobs_mc:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then + if self.timer>0.2 then + local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) + for k, obj in pairs(objs) do + if obj:get_luaentity() ~= nil then + if obj:get_luaentity().name ~= "mobs_mc:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then + local damage = 3 + minetest.sound_play("damage", {pos = pos}) + obj:punch(self.object, 1.0, { + full_punch_interval=1.0, + damage_groups={fleshy=damage}, + }, nil) + self.object:remove() + end + else local damage = 3 minetest.sound_play("damage", {pos = pos}) obj:punch(self.object, 1.0, { @@ -81,208 +100,203 @@ minetest.add_particle({ }, nil) self.object:remove() end - else - local damage = 3 - minetest.sound_play("damage", {pos = pos}) - obj:punch(self.object, 1.0, { - full_punch_interval=1.0, - damage_groups={fleshy=damage}, - }, nil) + end + end + + if self.lastpos.x~=nil then + if node.name ~= "air" then + minetest.sound_play("bowhit1", {pos = pos}) + minetest.add_item(self.lastpos, 'mobs_mc:arrow') self.object:remove() end end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end - if self.lastpos.x~=nil then - if node.name ~= "air" then - minetest.sound_play("bowhit1", {pos = pos}) - minetest.add_item(self.lastpos, 'mobs_mc:arrow') - self.object:remove() + + minetest.register_entity("mobs_mc:arrow_entity", THROWING_ARROW_ENTITY) + + + minetest.register_craft({ + output = 'mobs_mc:arrow 4', + recipe = { + {mobs_mc.items.flint}, + {mobs_mc.items.stick}, + {mobs_mc.items.feather}, + } + }) + + + arrows = { + {"mobs_mc:arrow", "mobs_mc:arrow_entity" }, + } + + local throwing_shoot_arrow = function(itemstack, player) + for _,arrow in ipairs(arrows) do + if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then + if not minetest.settings:get_bool("creative_mode") then + player:get_inventory():remove_item("main", arrow[1]) + end + local playerpos = player:getpos() + --local obj = minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2]) --current + local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2]) --mc + local dir = player:get_look_dir() + obj:setvelocity({x=dir.x*22, y=dir.y*22, z=dir.z*22}) + obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3}) + obj:setyaw(player:get_look_yaw()+math.pi) + minetest.sound_play("throwing_sound", {pos=playerpos}) + if obj:get_luaentity().player == "" then + obj:get_luaentity().player = player + end + obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name() + return true + end end + return false end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} end - -minetest.register_entity("mobs_mc:arrow_entity", THROWING_ARROW_ENTITY) - - -minetest.register_craft({ - output = 'mobs_mc:arrow 4', - recipe = { - {mobs_mc.items.flint}, - {mobs_mc.items.stick}, - {mobs_mc.items.feather}, - } -}) - - -arrows = { - {"mobs_mc:arrow", "mobs_mc:arrow_entity" }, -} - -local throwing_shoot_arrow = function(itemstack, player) - for _,arrow in ipairs(arrows) do - if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then - if not minetest.settings:get_bool("creative_mode") then - player:get_inventory():remove_item("main", arrow[1]) +if c("bow") then + minetest.register_tool("mobs_mc:bow_wood", { + description = "Bow", + inventory_image = "mobs_mc_bow.png", + on_use = function(itemstack, user, pointed_thing) + if throwing_shoot_arrow(itemstack, user, pointed_thing) then + if not minetest.settings:get_bool("creative_mode") then + itemstack:add_wear(65535/50) + end end - local playerpos = player:getpos() - --local obj = minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2]) --current - local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, arrow[2]) --mc - local dir = player:get_look_dir() - obj:setvelocity({x=dir.x*22, y=dir.y*22, z=dir.z*22}) - obj:setacceleration({x=dir.x*-3, y=-10, z=dir.z*-3}) - obj:setyaw(player:get_look_yaw()+math.pi) - minetest.sound_play("throwing_sound", {pos=playerpos}) - if obj:get_luaentity().player == "" then - obj:get_luaentity().player = player - end - obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name() - return true - end - end - return false + return itemstack + end, + }) + + minetest.register_craft({ + output = 'mobs_mc:bow_wood', + recipe = { + {mobs_mc.items.string, mobs_mc.items.stick, ''}, + {mobs_mc.items.string, '', mobs_mc.items.stick}, + {mobs_mc.items.string, mobs_mc.items.stick, ''}, + } + }) end -minetest.register_tool("mobs_mc:bow_wood", { - description = "Bow", - inventory_image = "mobs_mc_bow.png", - on_use = function(itemstack, user, pointed_thing) - if throwing_shoot_arrow(itemstack, user, pointed_thing) then - if not minetest.settings:get_bool("creative_mode") then - itemstack:add_wear(65535/50) - end - end - return itemstack - end, -}) - -minetest.register_craft({ - output = 'mobs_mc:bow_wood', - recipe = { - {mobs_mc.items.string, mobs_mc.items.stick, ''}, - {mobs_mc.items.string, '', mobs_mc.items.stick}, - {mobs_mc.items.string, mobs_mc.items.stick, ''}, - } -}) - -- egg throwing item -- egg entity -mobs:register_arrow("mobs_mc:egg_entity", { - visual = "sprite", - visual_size = {x=.5, y=.5}, - textures = {"mobs_chicken_egg.png"}, - velocity = 6, +if c("egg") then + mobs:register_arrow("mobs_mc:egg_entity", { + visual = "sprite", + visual_size = {x=.5, y=.5}, + textures = {"mobs_chicken_egg.png"}, + velocity = 6, - hit_player = function(self, player) - player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {}, - }, nil) - end, + hit_player = function(self, player) + player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {}, + }, nil) + end, - hit_mob = function(self, player) - player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {}, - }, nil) - end, + hit_mob = function(self, player) + player:punch(minetest.get_player_by_name(self.playername) or self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {}, + }, nil) + end, - hit_node = function(self, pos, node) + hit_node = function(self, pos, node) - if math.random(1, 10) > 1 then - return + if math.random(1, 10) > 1 then + return + end + + pos.y = pos.y + 1 + + local nod = minetest.get_node_or_nil(pos) + + if not nod + or not minetest.registered_nodes[nod.name] + or minetest.registered_nodes[nod.name].walkable == true then + return + end + + local mob = minetest.add_entity(pos, "mobs_mc:chicken") + local ent2 = mob:get_luaentity() + + mob:set_properties({ + visual_size = { + x = ent2.base_size.x / 2, + y = ent2.base_size.y / 2 + }, + collisionbox = { + ent2.base_colbox[1] / 2, + ent2.base_colbox[2] / 2, + ent2.base_colbox[3] / 2, + ent2.base_colbox[4] / 2, + ent2.base_colbox[5] / 2, + ent2.base_colbox[6] / 2 + }, + }) + + ent2.child = true + ent2.tamed = true + ent2.owner = self.playername end + }) - pos.y = pos.y + 1 + local egg_GRAVITY = 9 + local egg_VELOCITY = 19 - local nod = minetest.get_node_or_nil(pos) + -- shoot egg + local mobs_shoot_egg = function (item, player, pointed_thing) - if not nod - or not minetest.registered_nodes[nod.name] - or minetest.registered_nodes[nod.name].walkable == true then - return - end + local playerpos = player:getpos() - local mob = minetest.add_entity(pos, "mobs_mc:chicken") - local ent2 = mob:get_luaentity() - - mob:set_properties({ - visual_size = { - x = ent2.base_size.x / 2, - y = ent2.base_size.y / 2 - }, - collisionbox = { - ent2.base_colbox[1] / 2, - ent2.base_colbox[2] / 2, - ent2.base_colbox[3] / 2, - ent2.base_colbox[4] / 2, - ent2.base_colbox[5] / 2, - ent2.base_colbox[6] / 2 - }, + minetest.sound_play("default_place_node_hard", { + pos = playerpos, + gain = 1.0, + max_hear_distance = 5, }) - ent2.child = true - ent2.tamed = true - ent2.owner = self.playername + local obj = minetest.add_entity({ + x = playerpos.x, + y = playerpos.y +1.5, + z = playerpos.z + }, "mobs_mc:egg_entity") + + local ent = obj:get_luaentity() + local dir = player:get_look_dir() + + ent.velocity = egg_VELOCITY -- needed for api internal timing + ent.switch = 1 -- needed so that egg doesn't despawn straight away + + obj:setvelocity({ + x = dir.x * egg_VELOCITY, + y = dir.y * egg_VELOCITY, + z = dir.z * egg_VELOCITY + }) + + obj:setacceleration({ + x = dir.x * -3, + y = -egg_GRAVITY, + z = dir.z * -3 + }) + + -- pass player name to egg for chick ownership + local ent2 = obj:get_luaentity() + ent2.playername = player:get_player_name() + + item:take_item() + + return item end -}) -local egg_GRAVITY = 9 -local egg_VELOCITY = 19 - --- shoot egg -local mobs_shoot_egg = function (item, player, pointed_thing) - - local playerpos = player:getpos() - - minetest.sound_play("default_place_node_hard", { - pos = playerpos, - gain = 1.0, - max_hear_distance = 5, + minetest.register_craftitem("mobs_mc:egg", { + description = "Egg", + inventory_image = "mobs_chicken_egg.png", + on_use = mobs_shoot_egg, }) - - local obj = minetest.add_entity({ - x = playerpos.x, - y = playerpos.y +1.5, - z = playerpos.z - }, "mobs_mc:egg_entity") - - local ent = obj:get_luaentity() - local dir = player:get_look_dir() - - ent.velocity = egg_VELOCITY -- needed for api internal timing - ent.switch = 1 -- needed so that egg doesn't despawn straight away - - obj:setvelocity({ - x = dir.x * egg_VELOCITY, - y = dir.y * egg_VELOCITY, - z = dir.z * egg_VELOCITY - }) - - obj:setacceleration({ - x = dir.x * -3, - y = -egg_GRAVITY, - z = dir.z * -3 - }) - - -- pass player name to egg for chick ownership - local ent2 = obj:get_luaentity() - ent2.playername = player:get_player_name() - - item:take_item() - - return item end --- chicken -minetest.register_craftitem("mobs_mc:egg", { - description = "Egg", - inventory_image = "mobs_chicken_egg.png", - on_use = mobs_shoot_egg, -}) - --end maikerumine code if minetest.settings:get_bool("log_mods") then