Topic category: Help with Minecraft modding (Java Edition)
Hello guys.
"I want to create a Waystone algorithm with an encoding and decoding function using a procedure. Here's what I have done so far for the encoding:
The algorithm should take the X position of the player, then take the lengh of the number, and combine both as a single number. It then do the same for the Y and Z values, before adding "dim" and finally the "dimension". What I want to do is encode the position. Having one variable per coordinate means that we would need three variables per waypoint (and therefore per waystone). I want to encode them in a simple way. All we do is take the length of the coordinate and put it in front of the coordinate itself. If the number is negative, we just add a '0' before the length. So, for example, if we have X = 273.75, the encoded version of X would be '6273.75' because '273.75' has 6 characters. We repeat this process for each variable and put it all together. Therefore, for X = 273.75, Y = -42, and Z = -300.12, the encoding would be '6273.75034207300.12' and that's it. Note that the encoding is in string format, while the coordinates are in float.
For decoding, we do the opposite. Let's take this example: "6273.75034207300.12" The first digit "6" represents the length of the X variable, so we read the following six digits, which span over six characters. Therefore, X = 273.75. Next, we move on to the next set of digits. We observe a "0", indicating that the number must be negative. Then we see a "3", which means the first symbol is "-". The remaining two digits form the value of Y, which is "-42". We repeat the process for Z. We encounter a "0", indicating it is negative. Then we find a "7", and since we know the first symbol is "-", there are only six remaining symbols. Hence, Z = -300.12. It's so simple yet so hard to encode within Mcreator...
Can somebody helps me with the decoding part? It's getting really messy in my head.
This seems like an overly complicated format. Why don't you seperate each item with spaces?
In this case, storing a list of positions would look like:
273.75 -42 -300.12 minecraft:overworld -19.21 102 19.6 minecraft:the_end
This string would represent:
In this case, you can simply loop over the string split with spaces, and take every fourth item. If you wanted it to be even simpler, you could seperate multiple entries with a different seperator:
273.75 -42 -300.12 minecraft:overworld_-19.21 102 19.6 minecraft:the_end
I can provide Java code if you want it.
Yes provide please.
But I believe I have understood your point. The reason I don't separate the values with spaces is because I want to minimize memory usage. My intention is to add this mod to my server, and I want it to be memory-friendly.
I think you will be fine with the memory usage. The only times I have encountered an out-of-memory error is when I am doing crazy recursive things.
Anyways, here's some code:
To use this, create and save a new procedure called "Encoding", then press "Lock/unlock element code", and then double‐click on the procedure again. (Don't erase the "package com.mcreator..." line at the beginning.)
(new net.mcreator.yourmodnamehere.procedures.EncodingProcedure(x, y, z, dimension)).encode()
Then you can use this in any text-related block.net.mcreator.yourmodnamehere.procedures.EncodingProcedure location = net.mcreator.yourmodnamehere.procedures.EncodingProcedure.decode(YOURTEXTVARIABLENAME);
Then to get the x, y, z, and dimension properties, uselocation.x
location.y
location.z
location.dimension
thanks you 👍