Jump to content

Recommended Posts

Posted

I'm making a particle accelerator type thing, and it will be very massive, but I don't want to have a world.getblock for each block. That would get too crazy too fast. Is there an easier way to do this? ( it doesn't have to be easier just less huge)

The proud(ish) developer of Ancients

Posted

Yes, when the player completes the structure, the accelerator will work correctly. It's basically just a giant machine. I  don't know if I should check in onBlockActivated or updateTick.

The proud(ish) developer of Ancients

Posted

That actually is pretty challenging.  In some respects it is like a power system (like redstone) and in those systems each block checks its neighbors in sort of a distributed processing approach.  However, most power systems only implement a limited range because, as you might imagine, checking for all the possible connection paths over a large area quickly grows to require significant processing.

 

So you probably want a centralized approach, where some method checks the blocks for the pattern.  But this is only easy if some starting point or maybe center point is a special block that you can use to reference all the other locations.  Otherwise you'd have to constantly scan the world for any possible pattern that matches the structure, and that would again require a on of processing.

 

So my first suggestion is that, if you haven't already, you should make one special tile entity that is meant to form maybe the starting point or the control panel or the center of your particle accelerator.  Then that tile entity would have the job of detecting the completion with the idea that the rest of the structure is supposed to have a known relationship to the position of this tile entity.  (You could even do cool things like this tile entity could actually suggest where to place the next block.)

 

Then you'd be back to your original question: how to efficiently scan for completion of the particle accelerator.  I'm assuming your accelerator is made up of special blocks.  In that case you could have the tile entity check each time the custom block is placed.  If your tile entity started out with a "map" of the needed positions, then you'd just have to "check off" each needed block until they were all in place.  Like imagine that the tile entity had a list of all the relative positions that needed a block, and each time a block was placed you marked it as placed.  I think that would work pretty well performance-wise, because instead of scanning the whole space and using pattern matching logic, you'd have a preset pattern that you could check off quickly and only when a potential block has been placed. 

 

Not sure if you get what I mean, but the gist is that you have a tile entity that has a map of where things should be placed, then when blocks are placed you check off the positions on the map.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I was planning on using a centralized TileEntity to control if the structure was formed (just for an inventory). What type of variable should I use to save the structure map?

The proud(ish) developer of Ancients

Posted

I was planning on using a centralized TileEntity to control if the structure was formed (just for an inventory). What type of variable should I use to save the structure map?

 

There are lots of possible Java data structures like arrays, lists, maps, hashmaps, etc. that can each probably be used with different advantages to each.  they can also be combined, like array of lists, lists of arrays, etc.

 

I think if the map is sparse (i.e. the number of matching blocks is small compared to the overall area) then something like a list seems like it would be efficient since you'd only have entries for the blocks that actually matter.  I think if the map is dense then maybe more of an array.

 

I don't know what your structure really looks like, but for example imagine a list or array of chunk coordinates (you could even create a custom class containing the coordinates).  Then you'd just go through the list/array and check at each chunk coordinates.

 

Basically there are a lot of ways to approach this, you might have to play around until you get something you like.  I guess I would probably do this like: make a custom class containing coordinates and block type and a boolean for whether the block is placed or not.  Then make a list of that class, with each entry representing a block in the structure.  Then just cycle through the list marking the boolean in each entry.  Make sense?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.