Some stuff i cant undestand

Place to get help with not working mods / modding interface.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Some stuff i cant undestand

Post by RavenlStl »

First of all I'm sorry for my cry for help.

I'm trying to do a little mod of my own. It shoud be 1x2 chest i.e. ship container. A friend of mine helped with the graphics. Now i'm trying to make the code work. As usual for me i grab some other beautiful mods and frankensteinen them.
And so you know me and programming are on different ends of the stick.
So pleeeeeese help me couple things to understand

First is why the hell this is not working
table.insert(data.raw["technology"]["steel-processing"].effects,{type="unlock-recipe",recipe="ship-container"})
I see my item on the tech. Recipe is correct. Even locale works. But it does not apply in craft list. Not by hand not by assembler.

And the second one is big. It must have 2 different sprites cause it 1x2. I can figure this out how i shoud describe the entity.
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

RavenlStl wrote: Sat Aug 24, 2019 4:33 pm First of all I'm sorry for my cry for help.

I'm trying to do a little mod of my own. It shoud be 1x2 chest i.e. ship container. A friend of mine helped with the graphics. Now i'm trying to make the code work. As usual for me i grab some other beautiful mods and frankensteinen them.
And so you know me and programming are on different ends of the stick.
So pleeeeeese help me couple things to understand

First is why the hell this is not working
table.insert(data.raw["technology"]["steel-processing"].effects,{type="unlock-recipe",recipe="ship-container"})
I see my item on the tech. Recipe is correct. Even locale works. But it does not apply in craft list. Not by hand not by assembler.

And the second one is big. It must have 2 different sprites cause it 1x2. I can figure this out how i shoud describe the entity.
First thing to double check is just that that your ship-container recipe isn't set with "hidden = true" in its prototype. If it is, that'll override any other enabling done by the game. If you post your code, we can probably tell you what's wrong within a few seconds.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Code: Select all

data:extend(
{
  {
    type = "item",
    name = "ship-container",
    icon =  "__ShipContainer__/graphics/icons/ship-container.png", 
    icon_size = 32,
    subgroup = "storage",
    order = "aab",
    place_result = "ship-container",
    stack_size = 10
  },  
 }
)

Code: Select all

data:extend(
{
  {
    type = "recipe",
    name = "ship-container",
	enabled = false,
    ingredients =
	{
		{"iron-plate", 12},
		{"steel-plate", 8},
		{"iron-gear-wheel", 2},
		{"iron-rod", 2}
	},
    result = "ship-container"
  },
}
)
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

Did you add the recipe after you researched the tech? Try running /c game.player.force.reset_technology_effects() if you did.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Adamo wrote: Sat Aug 24, 2019 5:27 pm Did you add the recipe after you researched the tech? Try running /c game.player.force.reset_technology_effects() if you did.
Yep! Worked just fine! Thanks a lot!
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

RavenlStl wrote: Sat Aug 24, 2019 5:34 pm Yep! Worked just fine! Thanks a lot!
Great! As long as the recipe shows up in the tech tree, I think you can be confident that it will be enabled when someone researches the tech, but I've found the game to be inconsistent on whether it does this for new mods with recipes in techs that are already researched on the map. Well. not inconsistent, but I just haven't figured out the pattern, yet.
Last edited by Adamo on Sat Aug 24, 2019 5:36 pm, edited 1 time in total.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Now the real stuff...

I got this

Code: Select all

data:extend(
{
    {
    type = "container",
    name = "ship-container",
    icon = "__ShipContainer__/graphics/icons/ship-container.png",
    icon_size = 64,
    flags = {"placeable-neutral", "player-creation"},
    minable = {mining_time = 0.2, result = "ship-container"},
    inventory_size = 80,
	max_health = 700,
    corpse = "medium-remnants",
    open_sound = { filename = "__base__/sound/metallic-chest-open.ogg", volume=0.65 },
    close_sound = { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.7 },
    vehicle_impact_sound =  { filename = "__base__/sound/car-metal-impact.ogg", volume = 0.75 },	
    resistances = {{ type = "fire", percent = 90 }, { type = "impact", percent = 60 }},
    collision_box = {{-0.70, -0.70}, {0.70, 0.70}},
    selection_box = {{-1.0, -1.0}, {1.0, 1.0}},
    fast_replaceable_group = "container",
	scale_info_icons = 1,
    picture =
    {
      layers =
      {
        {
          filename = "__ShipContainer__/graphics/entity/ship-container.png",
          priority = "extra-high",
          width = 32,
          height = 40,
          shift = util.by_pixel(0, -1),
		  scale = 1,
        },
        {
          filename = "__ShipContainer__/graphics/entity/ship-container-shadow.png",
          priority = "extra-high",
          width = 56,
          height = 22,
          shift = util.by_pixel(12, 15),
          draw_as_shadow = true,
		  scale = 1,
        }
      }
    },
	circuit_wire_connection_point = circuit_connector_definitions["chest"].points,
    circuit_connector_sprites = circuit_connector_definitions["chest"].sprites,
    circuit_wire_max_distance = default_circuit_wire_max_distance
  }
  } 
)
And i got this

Code: Select all

	picture = {
	  north = {
		filename = "__ShipContainer__/graphics/entity/ship-container-h.png",
		priority = "high",
		shift = util.by_pixel(5, -18),
		width = 128,
		height = 80,
	  },
	  east = {
		filename = "__ShipContainer__/graphics/entity/ship-container-v.png",
		priority = "high",
		shift = util.by_pixel(31, -5),
		width = 64,
		height = 144,
	  },
	  south = {
		filename = "__ShipContainer__/graphics/entity/ship-container-h.png",
		priority = "high",
		shift = util.by_pixel(5, -18),
		width = 128,
		height = 80
	  },
		filename = "__ShipContainer__/graphics/entity/ship-container-v.png",
		priority = "high",
		shift = util.by_pixel(31, -5),
		width = 64,
		height = 144,
	  }
	}
And i'm too dumb to make it work together
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

Well, the last entry in your rotating sprite set needs to be set by "west = {", exactly like the other entries in the table. You seem to be missing that line.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Yeah its a mistypo,
but i got this two codes from different mods, and i really dont undertsnd how to cerrectly unite them and how to describe entity behavior.
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

RavenlStl wrote: Sat Aug 24, 2019 5:40 pm Yeah its a mistypo,
but i got this two codes from different mods, and i really dont undertsnd how to cerrectly unite them and how to describe entity behavior.
Have you tried just adding the "west = {" line where it needs to go, and then just removing the entire entry for the "picture" table in the first prototype and replacing it with the picture table in your second code snippet? I feel like it should work. You'll be removing the shadow, but one step at a time.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Error while loading entity prototype "ship-container" (container): Key "filename" not found in poperty tree at ROOT.container.ship-container.picture

Code: Select all

data:extend(
{
    {
    type = "container",
    name = "ship-container",
    icon = "__ShipContainer__/graphics/icons/ship-container.png",
    icon_size = 64,
    flags = {"placeable-neutral", "player-creation"},
    minable = {mining_time = 0.2, result = "ship-container"},
    inventory_size = 80,
	max_health = 700,
    corpse = "medium-remnants",
    open_sound = { filename = "__base__/sound/metallic-chest-open.ogg", volume=0.65 },
    close_sound = { filename = "__base__/sound/metallic-chest-close.ogg", volume = 0.7 },
    vehicle_impact_sound =  { filename = "__base__/sound/car-metal-impact.ogg", volume = 0.75 },	
    resistances = {{ type = "fire", percent = 90 }, { type = "impact", percent = 60 }},
    collision_box = {{-0.70, -0.70}, {0.70, 0.70}},
    selection_box = {{-1.0, -1.0}, {1.0, 1.0}},
    fast_replaceable_group = "container",
	scale_info_icons = 1,
	picture = {
	  north = {
		filename = "__ShipContainer__/graphics/entity/ship-container-h.png",
		priority = "high",
		shift = util.by_pixel(5, -18),
		width = 128,
		height = 80,
	  },
	  east = {
		filename = "__ShipContainer__/graphics/entity/ship-container-v.png",
		priority = "high",
		shift = util.by_pixel(31, -5),
		width = 64,
		height = 144,
	  },
	  south = {
		filename = "__ShipContainer__/graphics/entity/ship-container-h.png",
		priority = "high",
		shift = util.by_pixel(5, -18),
		width = 128,
		height = 80
	  },
	  west = {
		filename = "__ShipContainer__/graphics/entity/ship-container-v.png",
		priority = "high",
		shift = util.by_pixel(31, -5),
		width = 64,
		height = 144,
	  }
	},
	circuit_wire_connection_point = circuit_connector_definitions["chest"].points,
    circuit_connector_sprites = circuit_connector_definitions["chest"].sprites,
    circuit_wire_max_distance = default_circuit_wire_max_distance
  }
  } 
)
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

Oh, you know what? Look here: https://wiki.factorio.com/Prototype/Container

The container prototype only supports one picture, not a north,south,east,west 4-way sprite. Sorry. I don't think there's any way to take a sprite and turn it into a rotatable thing. You need a prototype that takes a 4-way sprite table to do that. You can still use layers to have shadows and other multi-layered sprites, but, doesn't look like you can do rotation. Here are all the things you can put in the picture table: https://wiki.factorio.com/Types/Sprite

One trick that maybe would work would be to put the 4way sprite into the integration_patch table and use an "empty" sprite for the sprite in "picture". That's a bit tricky and likely not recommended, but, as an advanced coder, I'd probably try it if I were in your position.

Another, likely better, option would be to see if another prototype other than "container" can still serve your purpose. One that takes a 4-way sprite table instead of a single picture sprite.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

Ok, at this point my mind is blown away)) For me its undoable, but anyway thanks a lot for the help!
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

RavenlStl wrote: Sat Aug 24, 2019 6:21 pm Ok, at this point my mind is blown away)) For me its undoable, but anyway thanks a lot for the help!
Well, it says pretty clearly the container prototype can't be rotated, but, you could consider just making two entities: a vertical one and a horizontal one. Or just choosing which direction you like more, and sticking to that. Then you would just make the picture table in your prototype call to that one file, either ship-container-v.png or ship-container-h.png.
RavenlStl
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Aug 23, 2019 8:41 pm
Contact:

Re: Some stuff i cant undestand

Post by RavenlStl »

by 2 entities you mean 2 different items to craft or is the way for game to pick one of them depending on rotation?
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

RavenlStl wrote: Sat Aug 24, 2019 7:56 pm by 2 entities you mean 2 different items to craft or is the way for game to pick one of them depending on rotation?
The simplest thing would just be to make two recipes, two items, and two entities -- one entity for each orientation -- and then add both recipes to the tech. This is because the container prototype doesn't allow rotating. Doing more than that will get tricky, but there are things you can try when you feel like you're ready. I would start with just making the two recipes, items, and entities, though.

If you decide to do this, you'll be at step two, where you need to look at the selection_box and collision_box values in your entity prototypes, and give them the correct coordinates for the size of the 2x1 sprite you're using.
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3237
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Some stuff i cant undestand

Post by BlueTemplar »

Could rotation (at least in hand) be achieved with some scripting trickery ?
(see "rotation" of landfill tiles... in... Dectorio ? Or was it Sea Block ..?)

(Does the game even have in-built support for rotation of non-square entities ?)
BobDiggity (mod-scenario-pack)
Adamo
Filter Inserter
Filter Inserter
Posts: 481
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: Some stuff i cant undestand

Post by Adamo »

BlueTemplar wrote: Sun Aug 25, 2019 7:33 am Could rotation (at least in hand) be achieved with some scripting trickery ?
I think so, yes. But before I mention the way that suggests itself to me, I point out that if I were solving your problem, I think I'd strongly look at finding another prototype that can pretend to be a container but also rotates. Here are all of the prototypes that are extended from EntityWithHealth:

https://wiki.factorio.com/Prototype/Ent ... Extensions

If I were going to try to script a way to rotate this container, one possible way that suggests itself to me is to create the two entities, and then setup a custom-input data prototype, like

Code: Select all

data:extend({
  {
    type = "custom-input",
    name = "rotate-ship-container",
    key_sequence = "SHIFT + R",
    consuming = "none"
  }
})
and then setup a hook in control.lua, something like

Code: Select all

script.on_event("rotate-ship-container",function(event)
-- check if player.selected is a container
-- check if space is clear to rotate container
-- store contents of container in a table of itemstack objects
-- remove container
-- create new container
-- put contents of table of itemstack objects into the new container
end)
This would ultimately result in you needing to press shift-r to rotate the container. If the container has a huge inventory size, depending on how you're manipulating the itemstacks, this could be a somewhat heavy code. I feel like there should be a way to just copy the inventory as a whole, then replace the new container's inventory with that once it's created, but I haven't figured a way to do that, yet. There are functions in the Factorio Standard Library mod for moving inventories, IIRC, if you want to see an example. To be clear, I wanted to answer your question, but I'm not really recommending this route. I think it would be more clever to find another prototype that rotates and will work for your purposes, if there is one.

Unfortunately, I'm looking through here, and I'm not seeing one. But I am not the cleverest one around. I wonder if we could somehow make it work as a cargo wagon. Maybe there's a way to make a rail wagon not need to go on tracks? Then it would be a matter of sizing it and setting it to be placed on grid.
Post Reply

Return to “Modding help”