How to create a blank inventory and creative recipes?

Place to get help with not working mods / modding interface.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

How to create a blank inventory and creative recipes?

Post by mrvn »

I want to write a mod to edit blueprints by walking around in them. I have a button on the screen where you can drop a blueprint to start editing it. The mod then creates a surface and teleports the player there. The mod is then supposed to create all the entities from the blueprint but I decided to start with a blank blue print first. So that's what I have so far. You drag&drop the blueprint and end up on a blank surface ready to create stuff.

Now I want to hide the players inventory and tool bar and replace them with a blank inventory and toolbar because editing the blueprint should neither take items from the inventory or add any to it. Also while editing the blueprint crafting should be free. Which means I need the creative recipes as used in the sanbox mode. And I need to hide the normal players crafting queue.

Can I do that and if so how?

One alternative idea I had was to maybe create a tutorial if I can somehow make that dynamically from the blueprint the player dropped on the button. In a tutorial the players inventory and crafting queue is already separate from the game. Is that an option?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to create a blank inventory and creative recipes?

Post by eradicator »

  1. Create the surface
  2. Create a new character on the new surface. (Possibly an associated character)
  3. Set the players character to the new character
  4. Set player.cheat_mode = true on the player.
  5. Deal with the original character on the original surface. (Hide, Make invulnerable)
When the player leaves the BP surface you just assign his old character back and disable cheat mode. That way the only thing you have to deal with is the "clone" (really the original) on the original surface that isn't actively controlled by anyone.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: How to create a blank inventory and creative recipes?

Post by mrvn »

That sounds simple. Thanks.

Making the player invulnerable though would be bad I think. You could just walk into an alien nest and then "hide" in the blueprint editor. Better might be to pause the blueprint editor when the real player character takes damage. Or make the dummy character take damage whenever the real one does. So the player knows he should quit editing and save himself.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to create a blank inventory and creative recipes?

Post by eradicator »

mrvn wrote:Making the player invulnerable though would be bad I think.
Well yea, you have to deal with the clone some way or another.
I don't see any benefit in walking into a nest and switching to BP mode though. Yes, you wouldn't take damage while editing the BP, but the moment you step back into the real world you're still in the middle of a nest and have to survive. The only edge case i can think of would be if you were almost dead in a multiplayer game - you could wait inside the BP until someone rescues you? That sounds like a rather edgy edge-case. Of course you could just skip the "make invulnerable" part altogether. I just put it in there to protect you from randomly dieing to trains/cars etc. With the new on_entity_damaged event from 0.16.17 transfering damage to the BP world or yanking the player back into the real world when they take damage certainly becomes an option too. Though when yanking people out forcefully you should probably save the intermediate BP somewhere. I don't think you have time to actually ask the player to come back, when you take damage in factorio you usually only have a few seconds left until you're dead. Also associated characters do get a corpse too i believe, so even if the original dies while the player is in a BP they wouldn't lose any items (except for the armor if it got destroyed).

Slightly off topic: Do you have any explanation how the player gets to the other surface btw? Personally i'd imagine it to be some kind of meditative/dream state.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: How to create a blank inventory and creative recipes?

Post by mrvn »

eradicator wrote:Slightly off topic: Do you have any explanation how the player gets to the other surface btw? Personally i'd imagine it to be some kind of meditative/dream state.
Virtual reality display in your helmet.
canisin
Inserter
Inserter
Posts: 31
Joined: Sat Dec 16, 2017 12:44 pm
Contact:

Re: How to create a blank inventory and creative recipes?

Post by canisin »

Hey there, I am coming from the other blueprint lab mod that you commented on! :D

Some very interesting ideas here.

First of all, I dealt with the lab behavior by not creating a new character for the player when they are teleported to the lab. It appears that the game assigns characterless players a temporary inventory that gets destroyed when the player is reattached to a character. That solves a whole nest of problems. By enabling cheat mode in the lab, as eradicator has also suggested, the player does not care about whatever was in their temporary lab inventory.

As for the "clone", i.e., the character that gets left behind in the real world when the player teleports to the lab, I have done nothing! :D I just left it there quite very vulnerable. The idea of somehow handling on_entity_damaged by maybe flashing the screen or yanking the player back to the world is great! As my lab is persistent, yanking back seems to be an ok solution. Adding a very small lab shield to the character would also be a nice qol improvement for using the lab.

Also, I have noted a few things that I need to go back and test in my mod:
- Porting to the lab while crafting. Also, while driving.
- Porting back with an item in your "hand".
Post Reply

Return to “Modding help”