# How to do the farming/smelting system like in Sky Block

If you haven’t played the game, there is a system which lets you farm and smelt items. There was also a game with similar system but I forgot the name. By trying to think of how they made the system, I have some questions. (NOTE: I WANT TO KNOW HOW THEY MIGHT HAVE DONE, NOT THE EXACT WAY)

1. How are the crops handled? Is it a table? If so, how are they still growing even if they are inside the table?

2. The same as question #1, is the smelting also a table? Is it a function or a loop? If so, how is it stored?

3. This connects to question 1 and 2, is it just one script or multiple scripts per island?

Thank you for those who will help and answer my questions.

5 Likes

This is a pretty complex system, and to know for sure we’d have to be in contact with the game’s creators which is very unlikely. Instead, it might be more beneficial to consider how they might have done it and how we could do it ourselves.

Let’s start with question 1 – how are crops (or, on a wider scale, block-by-block calculations) handled?

In many games which feature voxel or block-based worlds, there is a lot of data moving. If each tile were to even run a single, simple calculation each frame, player worlds with thousands of tiles would bog the game down to the point of unplayability.

So, many games (with Minecraft as the chief example) use a chunk system. This system groups together similar calculations of a large group of tiles and executes each once when necessary, and then distributes the result to all blocks inside the chunk.

How does this apply to crops growing? The chunk model can help us understand how many individual crops can grow over time without the need for thousands of calculations per second. Each chunk stores a list of all blocks the chunk contains. Every second (or half-second, or quarter-second, etc) the chunk runs a function on all its blocks. When a function is ran on that farm block, it increases a ‘growth’ counter. When the growth counter reaches an adequate value, the farm item grows.

Smelting likely uses a similar function that, instead of growing, increases a different counter that instead smelts the item.

In short, the chunk model is likely used to store and run scripts on just about everything in the game. All the blocks are stored in tables in each chunk, and each chunk is stored by a world script that handles large-scale calculations.

3 Likes

The crops can be handled many ways, if I were to do it I’d use a table that has the info of the amount of crops and how big they’ve grown, then again you can also use values if you like that.

I’d say there is a 76% chance that smelting is a table, you insert the item into the table, it then counts down and item is fully smelted. Then removing it from the table.

I’m 99.9987% sure that each island has multiple scripts. It’d be extremely difficult to make 1 script for each island.

1 Like

How is this function run? I get the point of making a timer system, but is it a loop? If it is a loop, how is it handle? (Main server script or sub script)

I’m 99.9987% sure that each island has multiple scripts. It’d be extremely difficult to make 1 script for each island.

Does this mean that when a player joins, a model of their own island is loaded, and the server just inserts all necessary scripts?

If you’re talking about loading the island, then probably its 1 script but if you’re talking about things like smelting and things on the island its more than 1

1 Like

Also, the growing of the plant is not simultaneously, so I think it is not a loop. Are there other ways to achieve this? (Like when you planted a seed, it has its own wait time, not growing simultaneously with other plants. Does it have to do with adding a function in the table?)

Sorry for the title, yes I was thinking how they might have did the system and not exactly what they did. I just can’t figure out a organized way to code it.

If I did it I would add a wait for each plant like so,

``````local Plant = script.Parent
local WaitInterval = 10 -- 10 Seconds per count
local PlantGrown = false
local PlantName = "AppleTree"
local PlantPercentage = Plant.Size.Y/1.5
local function GrowPlant(Plant,PlantName, WaitInterval, PlantGrown, PlantPercentage)
if PlantGrown == false and PlantName == "AppleTree" then
repeat
wait(WaitInterval)
PlantPercentage = PlantPercentage + 20 -- +20% every interval
Plant.Size = Vector3.new(Plant.Size.X, Plant.Size.Y + 1/5, Plant.Size.Z)
until PlantPercentage == 100
Plant.Size = Vector3.new(Plant.Size.X, math.ceil(Plant.Size.Y), Plant.Size.Z)
end
end
``````

Not the best way but, something like that…

1 Like

You easily store the time they got planted in a table, and through a while loop you constantly check the current time and the time they got planted

``````if Plants[i] - tick() >= TIME_LIMIT then plant.Grown = true end
``````

This is how it would work

1 Like

I actually haven’t thought about using tick, will try this.

I believe adding this function to multiple plants would cause server lag or memory leaks.

Making @Jimmyswift response as the solution, but thanks for the those who also responded!

1 Like