I have an event that adds a Block to a HashSet when right-clicking with a compass. However, I want to add all blocks of the same type connected to the first block to the set. How should I do this to prevent lag?
Iterate over all connected blocks of same type
1.3k Views Asked by Aly At
1
There are 1 best solutions below
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in ITERATOR
- Implementing Iterator for abstractCollection
- Const-correctness of self made iterators
- How entrySet() works internally in HashMap?
- Append Loop Variable to Variable Name
- java - how to create custom hashtable iterator?
- Recursive iterator for composite pattern
- How can I restart a string iterator endlessly?
- (*it).second. How this keyword works?
- Generate different period of time using joda
- upper_bound() gives WRONG output
- How to unzip an iterator?
- Iterating through multiple levels of Child Objects
- Is there a conventional iterator interface in Java which separates traversal from element access?
- Iterate over pairs of chunks without creating a temporary vector
- ListIterator last hasNext() something not understood
Related Questions in MINECRAFT
- Java sending handshake packets to minecraft server
- Minecraft Forge event.entity vs event.player
- Unsupported major.minor version 52.0 error when my spigot/bukkit plugin is run on the server
- Minecraft Modding Forge .isRemote() and worldObj
- My bukkit plugin won't load
- Minecraft Get the object from a list and be abbe to manipulate it
- Minecraft plugin sign reading
- Custom Armor Minecraft Forge 1.8 Armor Model Texture
- scala minecraft forgemod 'gradle runClient' gives runtime exception
- Java Minecraft Plugin command not working
- Minecraft plugin player name error
- Minecraft Plugin setMotd()
- How to load id list from config.yml?
- NullPointerException when trying to open SQLite connection
- Minecraft plugin WorldEdit get region
Related Questions in BUKKIT
- Error with TitleAPI.jar no NMS
- File is being made but FileConfiguration is not putting text in it
- Why is the inventory updating?
- Java (Bukkit) how to acces to the Config with out this?
- Java HashMap - String to bukkit Vector? How?
- Should YamlConfiguration objects be closed?
- Unsupported major.minor version 52.0 error when my spigot/bukkit plugin is run on the server
- My bukkit plugin won't load
- (BUKKIT) The method getTargetBlock isn't working
- How to load id list from config for player Inventory? [Bukkit]
- Minecraft plugin player name error
- Elseif never executing in onCommand
- How to load id list from config.yml?
- NullPointerException when trying to open SQLite connection
- Bukkit. Color support in chat (&) ? and Username onplayerjoin does not work?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
First of all, you make a
BlockFacearray which represents all the 6 sides of blocks. (Front, back, left, right, above, and underneath).Next, you make a private method that goes through all these blockfaces and checks if the block at that side if of the same type and adds these blocks to a list of blocks that are yet to be checked. We will use this list later.
In this method,
resultsis the Set of all Blocks that are connected to the block that was clicked with the compass,todois the list of blocks that are yet to be checked the same way.Finally you use the following method to go through all the blocks that are yet to be checked and call the private method above for all these blocks. This is the most efficient way I could come up with.
Note that you can not run these methods on an aSync thread, because this can lead to a
CurrentModificationExceptionand this can cause strange behavior in the game itself, depending on what you use it for.