Cannot edit values of Class when created using .JSON file

Json File


Tile + Tile Loader Class

when using the editPoz function in tile Class it changes the value of the tile but when assigning that tile to an array of tiles it reverts back to the JSON defined X and Y

int tileType = Mathf.RoundToInt(map[xLocMap, yLocMap]);
Tile tile = tiles[tileType];
tile.editPoz(j, i);
print(tile.locXPoz + " " + tile.locYPoz);
tilesInChunk[j + (i * size)] = tile;

You seem to try to store instance information within a class that is only used / designed to describe tile types. You only have one “Tile” instance for every tile type but not for every actual tile. Your “map” seems to only hold the index of the tile type that the tile at the specified position has. You then use this ID to get that one single “Tile” instance for this type. So it’s pointless to store any tile instance specific information in that class because you only have one “shared” instance for each type.

For example your second tile type is “Dirt” which has the index “1” inside your tiles List. So every tile inside your map that should be dirt will have an index of “1”. So when querying the type from the map you get a value of 1 for each dirt tile. So every dirt tile will just reference the one “Tile” instance in your tiles List.

I’m not sure you really understand what you’re doing here ^^. Just like in minecraft the actual terrain is just made up of blockIDs + some metadata. Each blockID corresponds to one particular block instance. The block class itself doesn’t have a position since it describes just the type of block. The class may have methods that you call for the actual functionality. However you usually have to pass the actual block position into the method. For example see [the updateTick method][1] which looks like this:

void updateTick(World world, int i, int j, int k, Random random) 

So you have to pass in the reference to the world as well as the x, y and z coordinates of the block that you want to run the tick on. The actual Block class doesn’t know about any block positions. The point here is that for every voxel in the game you only store a single byte which is the index to the block type. You don’t have an instance of the Block class for every block. That would be total overkill. A single chunk in MC consists of 65536 blocks (height 256, width/length 16). If an area of 16x16 chunks is loaded that are 16 million blocks. Since every block in the voxel grid is just a single byte we only need 16 MB of memory to store the whole blocks of all loaded chunks. Imagine you had a seperate class instance for every loaded block. A single class instance would have probably 100+ bytes. So it would require 1.6GB of memory. It also would take ages to create all those class instances. Instead MC stores just the blockID as well as an additional metadata byte which may be used for various things (on / off state, orientation, color variant, …) depending on the block type.
[1]: Block Class | Minecraft Modding Wiki | Fandom