EMC Link + hoppers/pipeworks now works I think

This commit is contained in:
ThePython 2024-02-29 07:56:32 -08:00
parent 04df97a241
commit d3658c63a4
4 changed files with 71 additions and 32 deletions

View File

@ -108,6 +108,7 @@ You can find the old textures and sounds by going back to previous commits in Gi
* Removed the ability to right click with stars to see the charge (made it more convenient to add the EMC Link)
* Bugfixes:
* Dark and Red Matter Armor display properly (and identically) in both games.
* `add_star_emc` now correctly works with negative energy values.
### v7.3 (not released yet because there's not enough)

View File

@ -3,22 +3,22 @@ local S = minetest.get_translator()
local formspec = table.concat({
"size[",(exchangeclone.mcl and 9 or 8),",9]",
"label[1,2;",S("Input"),"]",
"list[context;input;2,2;1,1;]",
"list[context;src;2,2;1,1;]",
"label[4,1;",S("Target"),"]",
"list[context;target;3,1;1,1;]",
"label[4,2;",S("Star"),"]",
"list[context;star;3,2;1,1;]",
"list[context;fuel;3,2;1,1;]",
"label[4,3;",S("Output"),"]",
"list[context;output;3,3;1,1;]",
"list[context;dst;3,3;1,1;]",
exchangeclone.inventory_formspec(0,5),
"listring[current_player;main]",
"listring[context;input]",
"listring[context;src]",
"listring[current_player;main]",
"listring[context;star]",
"listring[context;fuel]",
"listring[current_player;main]",
"listring[context;target]",
"listring[current_player;main]",
"listring[context;output]",
"listring[context;dst]",
})
if exchangeclone.mcl then
formspec = formspec..
@ -27,41 +27,38 @@ if exchangeclone.mcl then
end
local function link_action(pos)
minetest.log("woo")
local player
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local limit
local using_star
local input_stack = inv:get_stack("input", 1)
local input_stack = inv:get_stack("src", 1)
local stored_emc
local target = inv:get_stack("target", 1):get_name()
local output_stack = inv:get_stack("output", 1)
local output_stack = inv:get_stack("dst", 1)
local in_indiv_emc = exchangeclone.get_item_emc(input_stack:peek_item(1)) or 0
local target_emc = exchangeclone.get_item_emc(target)
local stack_max = ItemStack(target):get_stack_max()
local star_stack = inv:get_stack("star", 1)
local star_stack = inv:get_stack("fuel", 1)
if minetest.get_item_group(star_stack:get_name(), "klein_star") > 0 then
using_star = true
limit = exchangeclone.get_star_max(star_stack)
stored_emc = exchangeclone.get_star_itemstack_emc(star_stack)
minetest.log("oh no")
else
using_star = false
limit = exchangeclone.limit
player = minetest.get_player_by_name(meta:get_string("exchangeclone_placer"))
if not (player and player ~= "") then minetest.log(dump(meta:get_string("exchangeclone_placer"))) return end
stored_emc = exchangeclone.get_player_emc(player)
end
-- Construct
minetest.log(dump({target, output_stack:get_name()}))
if target ~= "" and (output_stack:is_empty() or exchangeclone.handle_alias(output_stack) == target) then
local out_count = math.min(stack_max - output_stack:get_count(), math.floor(stored_emc/target_emc))
if out_count > 0 then
inv:add_item("output", ItemStack(target.." "..out_count))
inv:add_item("dst", ItemStack(target.." "..out_count))
if using_star then
exchangeclone.add_star_emc(inv, "star", 1, star_stack, -out_count*target_emc)
minetest.log(dump({out_count = out_count, target_emc = target_emc}))
exchangeclone.add_star_emc(inv, "fuel", 1, -out_count*target_emc)
else
exchangeclone.add_player_emc(player, -out_count*target_emc)
end
@ -72,9 +69,9 @@ local function link_action(pos)
if not input_stack:is_empty() and stored_emc < limit then
local max_count = math.min(math.floor((limit - stored_emc)/in_indiv_emc), input_stack:get_count())
if max_count > 0 then
inv:remove_item("input", ItemStack(input_stack:get_name().." "..max_count))
inv:remove_item("src", ItemStack(input_stack:get_name().." "..max_count))
if using_star then
exchangeclone.add_star_emc(inv, "star", 1, max_count*in_indiv_emc)
exchangeclone.add_star_emc(inv, "fuel", 1, max_count*in_indiv_emc)
else
exchangeclone.add_player_emc(player, max_count*in_indiv_emc)
end
@ -82,7 +79,7 @@ local function link_action(pos)
end
local timer = minetest.get_node_timer(pos)
if inv:get_stack("input", 1):is_empty() and inv:get_stack("target", 1):is_empty() then
if inv:get_stack("src", 1):is_empty() and inv:get_stack("target", 1):is_empty() then
timer:stop()
else
if not timer:is_started() then
@ -95,11 +92,11 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if player and player.get_player_name and minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "star" then
if listname == "fuel" then
if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then
return stack:get_count()
end
elseif listname == "input" then
elseif listname == "src" then
local emc = exchangeclone.get_item_emc(stack)
if emc and emc > 0 then
return stack:get_count()
@ -138,21 +135,20 @@ end
minetest.register_node("exchangeclone:emc_link", {
description = "EMC Link\nAllows automation with personal EMC",
tiles = {"exchangeclone_emc_link.png"},
groups = {pickaxey=4, material_stone=1, cracky = 2, building_block = 1, level = exchangeclone.mtg and 2 or 0},
on_rightclick = on_rightclick,
groups = {pickaxey=4, material_stone=1, cracky = 2, building_block = 1, level = exchangeclone.mtg and 2 or 0, tubedevice = 1, tubedevice_receiver = 1, container = exchangeclone.mcl2 and 2 or 4},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("star", 1)
inv:set_size("input", 1)
inv:set_size("output", 1)
inv:set_size("fuel", 1)
inv:set_size("src", 1)
inv:set_size("dst", 1)
inv:set_size("target", 1)
meta:set_string("infotext", "EMC Link")
meta:set_string("formspec", formspec)
end,
can_dig = exchangeclone.can_dig,
after_dig_node = exchangeclone.drop_after_dig({"input", "star", "output"}),
on_blast = exchangeclone.on_blast({"input", "star", "output"}),
after_dig_node = exchangeclone.drop_after_dig({"src", "fuel", "dst"}),
on_blast = exchangeclone.on_blast({"src", "fuel", "dst"}),
after_place_node = function(pos, player, itemstack, pointed_thing)
local player_name = player:get_player_name()
local meta = minetest.get_meta(pos)
@ -172,4 +168,46 @@ minetest.register_node("exchangeclone:emc_link", {
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})
_mcl_hoppers_on_try_pull = exchangeclone.mcl2_hoppers_on_try_pull(),
_mcl_hoppers_on_try_push = exchangeclone.mcl2_hoppers_on_try_push(nil, function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end),
_mcl_hoppers_on_after_push = function(pos)
minetest.get_node_timer(pos):start(1.0)
end,
_on_hopper_in = exchangeclone.mcla_on_hopper_in(
nil,
function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end
),
})
if exchangeclone.pipeworks then
local function get_list(direction)
return (direction.y == 0 and "src") or "fuel"
end
minetest.override_item("exchangeclone:emc_link", {
tube = {
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1},
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local result = inv:add_item(get_list(direction), stack)
if result then
link_action(pos)
end
return result
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if get_list(direction) == "fuel" then
if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then
return inv:room_for_item("fuel", stack)
end
else
return inv:room_for_item("src", stack)
end
end,
},
on_rotate = pipeworks.on_rotate,
})
end

View File

@ -26,7 +26,7 @@ hopper:add_container({
})
hopper:add_container({
{"top", "exchangeclone:emc_link", "output"},
{"bottom", "exchangeclone:emc_link", "input"},
{"side", "exchangeclone:emc_link", "input"},
{"top", "exchangeclone:emc_link", "dst"},
{"bottom", "exchangeclone:emc_link", "src"},
{"side", "exchangeclone:emc_link", "fuel"},
})

View File

@ -155,7 +155,7 @@ end
-- Adds to the amount of EMC in a star in a specific inventory slot
function exchangeclone.add_star_emc(inventory, listname, index, amount)
if not inventory or not amount or amount < 0 then return end
if not (inventory and listname and index and amount) then return end
if not listname then listname = "main" end
if not index then index = 1 end
local itemstack = inventory:get_stack(listname, index)