Skip to content
This repository was archived by the owner on May 23, 2022. It is now read-only.

Added support for recipes with the same item in core and injectors - #2

Open
mateuszdevs wants to merge 7 commits into
sedlak477:masterfrom
mateuszdevs:master
Open

Added support for recipes with the same item in core and injectors#2
mateuszdevs wants to merge 7 commits into
sedlak477:masterfrom
mateuszdevs:master

Conversation

@mateuszdevs

Copy link
Copy Markdown

Added support for recipes that have the same item in core and injectors
Added the chaotic core recipe as well in new format, however not sure if the recipe is correct since i dont play atm3 - assumed to be standard DE hardmode recipe

Fixed crafting for recipes with the same core and injector item
Changed recipe structure to work with new crafting code
Added Chaotic core recipe
fixed example recipe format
Comment thread fusioncrafter.lua Outdated
@sedlak477

Copy link
Copy Markdown
Owner

Thank you for your contribution, I like it very much 😄

I just found a little error, but that should be quickly resolved. I'll merge your pull request as soon as it's fixed. 👍

@sedlak477

Copy link
Copy Markdown
Owner

Also I like the checkboxes in the README, great addition 😉

Co-authored-by: Michael Sedlak <[email protected]>
@mateuszdevs

Copy link
Copy Markdown
Author

Thank you for your contribution, I like it very much 😄

no worries 😄

I just found a little error, but that should be quickly resolved. I'll merge your pull request as soon as it's fixed. 👍

Yeah just realised that, i noticed when i was testing in my world and updated the script on there, but forgot to put that up, my bad 😅

@AbyssDarkstar

Copy link
Copy Markdown

Sorry to intrude on the PR, but I have just last night made an almost identical change with one major difference.

This change here takes the core item out of the input list, meaning that if you put everything but the core item into the input chest, the program will attempt to craft the recipe, but never be able to... probably a mute point, but as I also have a fix for the item metadata to enable the Reactor Stabilizer crafting and similar, I would like to know how you would prefer I submit the changes...

  1. Wait for this PR to be merged, then apply my changes and submit my own PR.
  2. Submit my PR straight away, without my version of the same item in core and injectors fix.
  3. Submit my PR straight away, including my change to the core and injectors fix.

@sedlak477

Copy link
Copy Markdown
Owner

This change here takes the core item out of the input list, meaning that if you put everything but the core item into the input chest, the program will attempt to craft the recipe, but never be able to.

You have a good point there, this needs to be fixed. Adding an additional check to the canCraft function will probably suffice, but if your solution is cleaner feel free to share it here. 😄

I also have a fix for the item metadata to enable the Reactor Stabilizer crafting and similar

Wow that's great! 👍
I'd like to merge this PR after all the bugs are fixed, unless some major changes occur. If everything goes well you can wait for it to be merged, shouldn't take too long and then add your changes to avoid conflicts. But if you don't wanna wait, you can also create a new PR with your metadata fix (if that's possible) to discuss these changes there.

@AbyssDarkstar

Copy link
Copy Markdown

My solution to the Same items in core and injectors is to, like KasKatto, add the quantity into the core bit of the recipe entry in config, for example

{
	output = { ["draconicevolution:wyvern_core"] = 1 },
	input = {
		["draconicevolution:draconic_core"] = 5,
		["draconicevolution:draconium_block"] = 2,
		["minecraft:nether_star"] = 2,
		["minecraft:emerald_block"] = 1
	},
	core = { ["minecraft:emerald_block"] = 1 },
	name = "Wyvern Core"
}

Then in craft, transfer the core item over first, and the rest later

local function craft(recipe)
  -- Tell the user what we are doing
  local resultString = ""
  local coreItem = ""
  local coreAmount = 0
  io.write("Crafting " .. recipe.name .. "...")

  for item, amount in pairs(recipe.core) do
    coreItem = item
    coreAmount = amount
    transfer(item, amount, input, core)
  end

  -- Put input items into their places
  for item, amount in pairs(recipe.input) do
    -- If the item is a core item, and has been moved to the core completely, just skip it and move on
    if item == coreItem and amount == coreAmount then
    else  -- Else put it into the injectors
      transfer(item, amount, input, injectors)
    end
  end

  -- Wait for output
  waitItems(result, recipe.output)

  -- Transfer items to output inventory
  for item, amount in pairs(recipe.output) do
    transfer(item, amount, result, output)
  end

  print(" Done")
end

This snippet also includes my changes to display a friendly name instead of the fully qualified name

@sedlak477

Copy link
Copy Markdown
Owner

Yeah it's pretty similar to KasKatto's solution, but if in the config there were two or more items in the core then there's a possibility for the program to crash, because it tries to transfer the items twice. You could add a check in the beginning to ensure there is always only one item in the core, but I think we just keep KasKatto's solution and add a check to the canCraft function, because it's easier. For example something like this:

local function canCraft(recipe)
  -- Check for injector items
  for id, neededAmount in pairs(recipe.input) do
    local availableAmount = getItemAmount(id, input)

    if availableAmount < neededAmount then
      return false
    end
  end

  -- Check for core items (new)
  for id, neededAmount in pairs(recipe.core) do
    local availableAmount = getItemAmount(id, input)

    if availableAmount < neededAmount then
      return false
    end
  end

  return true
end

And the rest (friendly names, metadata fix) we just make a new PR and merge these changes from there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants