add piglin trading

This commit is contained in:
epCode 2021-03-25 15:29:04 -07:00
parent 88bc20d521
commit 34cb3aa0da
1 changed files with 101 additions and 11 deletions

View File

@ -3,13 +3,18 @@
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
local trading_items = {
{ itemstring = "mcl_core:obsidian", amount_min = 1, amount_max = 1 },
{ itemstring = "mcl_core:gravel", amount_min = 8, amount_max = 16 },
{ itemstring = "mcl_mobitems:leather", amount_min = 4, amount_max = 10 },
}
local S = minetest.get_translator("extra_mobs")
local mod_bows = minetest.get_modpath("mcl_bows") ~= nil
--###################
--################### piglin
--###################
local piglin = {
type = "monster",
passive = false,
@ -39,17 +44,11 @@ local piglin = {
walk_velocity = 4.317,
run_velocity = 5.6121,
drops = {
{name = "mcl_mobsitems:leather",
chance = 1,
min = 0,
{name = "mcl_bows:crossbow",
chance = 10,
min = 1,
max = 1,},
},
drops = {
{name = "mcl_mobitems:porkchop",
chance = 1,
min = 2,
max = 4,},
},
animation = {
stand_speed = 30,
walk_speed = 30,
@ -64,9 +63,24 @@ local piglin = {
fear_height = 4,
view_range = 16,
on_spawn = function(self)
self.gold_items = 0
self.weapon = self.base_texture[2]
self.object:set_bone_position("Wield_Item", vector.new(-1.5,7,1.5), vector.new(170,90,90))
end,
do_custom = function(self)
if self.trading == true then
self.state = "trading"
self.object:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(20,-20,18))
self.object:set_bone_position("Head", vector.new(0,6.3,0), vector.new(-40,0,0))
self.base_texture[2] = "default_gold_ingot.png"
self.object:set_properties({textures = self.base_texture})
else
self.base_texture[2] = self.weapon
self.object:set_properties({textures = self.base_texture})
self.object:set_bone_position("Head", vector.new(0,6.3,0), vector.new(0,0,0))
self.object:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(0,0,0))
end
if self.state ~= "attack" then
self._attacked_by_player = false
end
@ -81,6 +95,28 @@ local piglin = {
end
end
end
end,
on_rightclick = function(self, clicker)
if clicker:is_player() and clicker:get_wielded_item():get_name() == "mcl_core:gold_ingot" and self.state ~= "attack" then
local item_gold = clicker:get_wielded_item()
self.state = "stand"
mobs:set_animation(self, "stand")
item_gold:take_item()
self.trading = true
self.gold_items = self.gold_items + 1
minetest.after(5, function()
self.gold_items = self.gold_items - 1
if self.gold_items == 0 then
self.trading = false
self.state = "stand"
end
self.object:get_pos() = clicker:get_pos()
self.what_traded = trading_items[math.random(#trading_items)]
for x = 1, math.random(self.what_traded.amount_min, self.what_traded.amount_max) do
minetest.add_item({x=math.random(c_pos.x - 1, c_pos.x + 1), y=math.random(c_pos.y - 1, c_pos.y + 1), z= math.random(c_pos.z - 1, c_pos.z + 1)}, self.what_traded.itemstring)
end
end)
end
end,
do_punch = function(self, hitter)
if hitter:is_player() then
@ -105,8 +141,62 @@ local piglin = {
mobs:register_mob("extra_mobs:piglin", piglin)
local sword_piglin = table.copy(piglin)
sword_piglin.mesh = "mcl_armor_character.b3d"
sword_piglin.textures = {"extra_mobs_sword_piglin.png", "default_tool_goldsword.png", "extra_mobs_trans.png"}
sword_piglin.on_spawn = function()
return
end
sword_piglin.attack_type = "dogfight"
sword_piglin.animation = {
stand_speed = 30,
walk_speed = 30,
punch_speed = 45,
run_speed = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 440,
run_end = 459,
punch_start = 189,
punch_end = 198,
}
mobs:register_mob("extra_mobs:sword_piglin", sword_piglin)
local zombified_piglin = table.copy(piglin)
zombified_piglin.fire_resistant = 1
zombified_piglin.do_custom = function()
return
end
zombified_piglin.attacks_monsters = true
zombified_piglin.lava_damage = 0
zombified_piglin.fire_damage = 0
zombified_piglin.attack_animals = true
sword_piglin.mesh = "mcl_armor_character.b3d"
sword_piglin.textures = {"extra_mobs_zombified_piglin.png", "default_tool_goldsword.png", "extra_mobs_trans.png"}
sword_piglin.on_spawn = function()
return
end
sword_piglin.attack_type = "dogfight"
sword_piglin.animation = {
stand_speed = 30,
walk_speed = 30,
punch_speed = 45,
run_speed = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 440,
run_end = 459,
punch_start = 189,
punch_end = 198,
}
mobs:register_mob("extra_mobs:zombified_piglin", zombified_piglin)
-- Regular spawning in the Nether
mobs:spawn_specific("extra_mobs:piglin", {"mcl_nether:netherrack"}, {"air"}, 0, minetest.LIGHT_MAX+1, 30, 6000, 3, mcl_vars.mg_nether_min, mcl_vars.mg_nether_max)
-- spawn eggs
mobs:register_egg("extra_mobs:piglin", S("piglin"), "extra_mobs_spawn_icon_piglin.png", 0)