Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clone and simulate moving items and fluids to a peripheral #1839

Open
Burkino opened this issue May 24, 2024 · 9 comments
Open

Clone and simulate moving items and fluids to a peripheral #1839

Burkino opened this issue May 24, 2024 · 9 comments
Labels
area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature. feedback wanted Tell me what you want, what you really really want. wontfix A bug which I won't fix or an enhancement which won't be implemented.

Comments

@Burkino
Copy link

Burkino commented May 24, 2024

Currently there is no good way of moving a set of items to a peripheral while being confident all items will be moved. For this I would need a way to test what will happen before doing it for real. This is especially necessary for when you can't take items and fluids back out of input slots.
I believe the easiest way for the user would be to have a peripheral.virtual(name) function that clones the peripheral (including its inventory and tanks), then have some way of pushing fake items and fluids into it.

local TARGET = "minecraft:chest_0"

local fake = peripheral.virtual(TARGET)

--- @class Input
--- @field name string
--- @field amount number
--- @field type "item"|"fluid"

local to_test = { --- @type table<Input>
  {name="minecraft:cobblestone", amount=32, type="item"},
  {name="minecraft:water", amount=1000, type="fluid"}
}

--- @param inputs table<Input>
--- @return boolean
local function test(inputs)
  for _,v in pairs(inputs) do
    if v.type == "item" then
      local moved = fake.simulate_push_items(v)
      if moved ~= v.amount then
        return false
      end
    elseif v.type == "fluid" then
      local moved = fake.simulate_push_fluids(v)
      if moved ~= v.amount then
        return false
      end
    end
  end

  return true
end

if test(to_test) then
  -- Move items and fluids for real
else
  print("You can't move fluids into a chest")
end
@Burkino Burkino added the enhancement An extension of a feature or a new feature. label May 24, 2024
@Wojbie
Copy link
Contributor

Wojbie commented May 24, 2024

Could you expand on in which situations you could be not 100% sure it will be moved or not? If you know exactly what state target and source inventories/tanks are you should be able to predict if that move call will succeed fully, partially or not at all.

@Lupus590
Copy link
Contributor

How does this virtual peripheral know how the real one would behave to thus simulate that behaviour? I think that a better way would be to calculate the free space remaining in the real peripheral before the push/pull.

Or maybe, if this is possible on the Java side, the push/pull methods should have a flag to abort the transfer of fluids/items if the transfer would be partially complete.

@Wojbie
Copy link
Contributor

Wojbie commented May 24, 2024

Or maybe, if this is possible on the Java side, the push/pull methods should have a flag to abort the transfer of fluids/items if the transfer would be partially complete.

Or argument to indicate minimal amount to transfer to counterpoint with limit argument.

@Burkino
Copy link
Author

Burkino commented May 24, 2024

Could you expand on in which situations you could be not 100% sure it will be moved or not? If you know exactly what state target and source inventories/tanks are you should be able to predict if that move call will succeed fully, partially or not at all.

This is mostly for use in GregTech machines. There are dozens of machines with different amounts of input slots so it would be a huge pain to say what the input slots are. You would have to consider partially full slots and items rolling over to the next slot. Being able to simulate what would happen would greatly simplify the problem.
It's not entirely impossible, but it's a lot of extra work that would undoubtedly have some issue.

Or argument to indicate minimal amount to transfer to counterpoint with limit argument.

This wouldn't be a great solution, if you need to move 5 types of items and the 3rd one fails, you would need to backtrack, take the first 2 out, then try another machine.

@Lupus590
Copy link
Contributor

Why not just take the free space in the slot and use that as the limit for the transfer?

@fatboychummy
Copy link
Contributor

fatboychummy commented May 25, 2024

Do gregtech machines not show up as different peripheral types to CC? It makes no sense to me that you're trying to essentially brute-force find what machine a recipe should be for (at least, from the little explanation you've given, this is what it sounds like you're trying to do). You know the recipe, you know the machine, only push the recipe ingredients to the right machine?

This is how systems like AE2's ME does it, you cannot just push a recipe to any machine without care, you must designate a machine for every recipe.

@Burkino
Copy link
Author

Burkino commented May 25, 2024

Do gregtech machines not show up as different peripheral types to CC? It makes no sense to me that you're trying to essentially brute-force find what machine a recipe should be for (at least, from the little explanation you've given, this is what it sounds like you're trying to do). You know the recipe, you know the machine, only push the recipe ingredients to the right machine?

This is how systems like AE2's ME does it, you cannot just push a recipe to any machine without care, you must designate a machine for every recipe.

I have already encoded recipes and the type of machine it uses, I just need some way of checking that all the ingredients for the recipe will be pushed into the machine.

@Wojbie
Copy link
Contributor

Wojbie commented May 25, 2024

So can't you look in machine input and detect if they will fit or not? I am sorry if we seem repetitive but solution just seem to be to look at machine inputs state and calculate if they will fit, and i wonder if there is something about gregtech that stops you from doing that?

@Burkino
Copy link
Author

Burkino commented May 25, 2024

So can't you look in machine input and detect if they will fit or not? I am sorry if we seem repetitive but solution just seem to be to look at machine inputs state and calculate if they will fit, and i wonder if there is something about gregtech that stops you from doing that?

Like I said, I could probably do that, but just being able to simulate what would happen would greatly simplify the problem

@SquidDev SquidDev added feedback wanted Tell me what you want, what you really really want. area-Minecraft This affects CC's Minecraft-specific content. labels May 26, 2024
@SquidDev SquidDev added the wontfix A bug which I won't fix or an enhancement which won't be implemented. label Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Minecraft This affects CC's Minecraft-specific content. enhancement An extension of a feature or a new feature. feedback wanted Tell me what you want, what you really really want. wontfix A bug which I won't fix or an enhancement which won't be implemented.
Projects
None yet
Development

No branches or pull requests

5 participants