Alright once more progress has occurred. We can now load up schematics into the world and save the world as schematic back again. Also I wrote a little profiler to have a look to how fast stuff goes in ms:
Code:
Program start 1393366106562
Parsing and linking 410
World 396
Block 149
Chunk 1
Loaded schematic 316
Set world 81
Get world 132
Saved schematic 28
Up until the gap are constant times, but the remaining ones suffer greatly because of the big (61x42x59) schematic. This is how fast a player's statue would be:
Code:
Loaded schematic 4
Loaded world 21
Get world 57
Saved schematic 2
Note this does not yet contain tickUpdates, which will use reflection far more extensively, yet I'm pleased with these times.
Now to explain the abundance of overly joyous emotions. Basically,
the first block updates have happened! The very first update was caused by a redstone torch in this circuit:
I was testing with setBlock and eventually got it working, there's a flag you can use to update blocks after setting it. I turned it to 0 while trying to get it working. When it did, I tried it with updating and got this.
Note that this isn't actually attached to any GUI yet, I just saved to schematic and loaded that up with the deprecated Java GUI. I've also attached minecraft's own Profiler while trying to get setBlock working, so now my output looks like this;
Code:
SIM PROFILER:
Program start 1393428289252
Parsing and linking 401
Minecraft profiler 266
Block 207
Chunk 6
World 53
Loaded schematic 5
Set world 7
Set block 6
Get world 3
Saved schematic 1
MINECRAFT PROFILER:
Profiler test 4597
checkLight 115296
HURRAY once more!
Glory to all! Rejoice!
MILESTONE ACHIEVED!!!
So
it works for redstone!
The green edges are my cursor selection that has a bug in it I'm not bothering to fix. Here's water flowing around the ORE logo:
Apologies that the water doesn't make much sense, it shouldn't be upside down, but I made the schematic without thinking about orientation and ended up flipping it with photoshop (and also enlarging it a bit).
For those interested, he's what's happening in MC's profiler:
Code:
MINECRAFT PROFILER:
cleaning 347415
ticking 28734790
ticking.checkLight 795187
checkLight 93462
Right now it crashes when I think entities are created, but for the majority of its use, tickUpdates works perfectly. I might later also use tick itself (it crashes atm) if I ever want to simulate almost all farms. Not sure what I'll do next now, so many options..
Alright, busyness was had and a little progress has been made. But first a little background. The way the world used to be loaded was first the schematic is parsed and put into a World object containing the byte arrays for block ids and data, that is passed to the actual loader.
That was working fine until I thought about how I'd do TileEntities and Entities, as I didn't want to make a ton of objects for all the different kinds and load them separately.. bah. So my plan now is to load in the schematic itself, rather than converting to an object. The reasoning is that I might be able to use (I really hope so) the NBT tags of every TileEntity, convert them to NBTTagCompound objects inside minecraft and use the games own loading methods to add them to the world. There's a function readily available for that.
Other than that, there was this odd bug that would sometimes scramble a loaded schematic. I hopped on the server today to clear my head, and I had a moment of clarity. See if you can spot the pattern:
After fixing it, I immediately went to see if the storage room would work. Go see for yourself:
http://i.imgur.com/kji3p0f.gif
EDIT: Just to clarify, it did this before as well, so hereby I've discovered a new bug. For tomorrow.
If you want to look there may be a bit better way of loading the schematic I can give you a like to a mod API for forge (should be simple to get it to work with out it) the allows importing or schematic at run time of the mod it's in which in this case at schematic load load it. But to really see if its better I would have to see your code and I don't really want too. I have so much code to work on right now as it is. (Recoding Additional Crafting from scratch.)
Well Chibill, I've already thought about what you suggested. This whole project would be a lot easier if I would use or make a mod that contains relevant functions. But then, all the users would have to install that mod, and the simulation wouldn't be completely vanilla. Further, I've been designing it as such that when MCP updates, the Sim works (currently there's still a couple obfuscated things), can't wait until the mods update. Currently the loading in schematic code is fine and runs in well under a millisecond, I'm using a Tag-class that I found on the wiki years ago.
EDIT:
Geez the errors I get.. xD
I was asked to produce the simulator because it would be helpful in a project. So here's the download:
https://www.dropbox.com/s/j6mpv1r795qqhot/RSsim.jar
This is only the GUI, the actual simulating is not implemented. I was in the middle of refactoring when this jar was compiled, so the layer markers wouldn't work. Not everything is drawn yet, but it works for these:
- Buttons
- Comparators
- Glass
- Hoppers
- Pressure plates
- Repeaters
- Redstone torches
- Wires
- Slabs (green)
- Water
You can export png's and gifs. The checkbox will upload all of them to imgur, but the links are discarded.
Just to be clear again, I might integrate basic simulating into this GUI, however the plan is to move to a C++ GUI environment, because I need it to be able to do fancy stuff. So have fun with it guys.
EDIT: Oh I forgot, it will also ask you for minecraft.jar and some MCP files. Those is not really needed, so you can just cancel those. If you do happen to have the latest version of MCP and the correct minecraft.jar, it will load up a world in the background and do nothing with it (since I branched the simulator part from there).