java.lang.Object
net.rodofire.easierworldcreator.blockdata.blocklist.basic.comparator.BlockListComparator<T,U,V,W>
Type Parameters:
T - The type of the BlockListManager that will be managed by the comparator
U - The type of the BlockData. This represents everything to describe the Block. Usually, it would be BlockState. But there are some cases that require more data like NbtCompounds.
V - The type of the OrderedBlockListComparator (class to manage BlockList where the BlockPos are ordered no matter the BlockData, contrary to this class where each BlockPos are organized depending on the BlockData), related to the object so that no data is lost, or no incompatibilities are present
W - The type of the BlockData, like <U>, but for the OrderedBlockListComparator. Copy and paste the object that is required to the related OrderedBlockListComparator
Direct Known Subclasses:
CompoundBlockListComparator, DefaultBlockListComparator, ForceBlockListComparator, FullBlockListComparator

public abstract class BlockListComparator<T extends DefaultBlockList,U,V extends OrderedBlockListComparator<W>,W> extends Object

Class to manage a List<BlockList>. It is composed of a list of BlockLists and a Map of indexes.

For better performance:
  • Instead of searching for a BlockState inside the list, we use the indexMap.
  • The map allows us to get the place of the related BlockState in the posList.
  • Instead of having a time complexity of O(n), we get O(1) by using only a small amount of memory in more.

The class provides some useful methods:
  • avoid the duplicate of BlockState (that can be pretty annoying or counterproductive as well as having a performance impact in the case where a lot BlockState are duplicated).
  • ability to sort each BlockPos related to one T
  • convert this BlockListManager into a OrderedBlockListComparator that would allow for more flexibility on how are the BlockPos kept
  • provides some custom getters.
  • Field Details

    • blockLists

      protected List<T extends DefaultBlockList> blockLists
      the List of BlockList that are managed
    • indexes

      protected final Map<net.minecraft.block.BlockState,U> indexes
      Map used for better performance:
      • Instead of searching for a BlockState inside the list, we use the indexMap.
      • The map allows us to get the place of the related BlockState in the posList.
      • Instead of having a time complexity of O(n), we get O(1) by using only a small amount of memory in more.

      Params: <U> The type of the BlockData. This represents everything to describe the Block. Usually, it would be BlockState. But there are some cases that require more data like NbtCompounds.

  • Constructor Details

    • BlockListComparator

      public BlockListComparator(List<T> blockLists)
      init a comparator
      Parameters:
      blockLists - the list of blockList that will be indexed
    • BlockListComparator

      public BlockListComparator(T blockList)
      init a comparator
      Parameters:
      blockList - a blockList that will be indexed
    • BlockListComparator

      public BlockListComparator()
      init an empty comparator
  • Method Details

    • initIndexes

      protected abstract void initIndexes()
      method tu initialize the indexes.
    • put

      @SafeVarargs public final void put(List<T>... lists)
      method to combine a number of List<T>
      Parameters:
      lists - the list to combine
    • put

      public void put(List<T> blockLists)
      add a List of BlockList
      Parameters:
      blockLists - the list that will be put
    • put

      public abstract void put(T type)
      add a BlockList to the list
      Parameters:
      type - the blockList that will be added
    • get

      public List<T> get()
      method to get the list
      Returns:
      the list of the comparator
    • get

      public T get(int index)
      method to get a DefaultBlockList based on the index
      Parameters:
      index - the index that will be used to get the DefaultBlockList
      Returns:
      the DefaultBlockList related to the index
    • getFirst

      public T getFirst()
      method to get the first DefaultBlockList of the list
      Returns:
      the first DefaultBlockList of the list
    • getLast

      public T getLast()
      method to get the last DefaultBlockList of the list
      Returns:
      the last DefaultBlockList of the list
    • getRandom

      public T getRandom()
      method to get a random DefaultBlockList of the list
      Returns:
      a random DefaultBlockList of the list
    • getRandom

      public T getRandom(net.minecraft.util.math.random.Random random)
      method to get a random DefaultBlockList of the list
      Parameters:
      random - the random object that will be used to get the index
      Returns:
      a random DefaultBlockList of the list
    • size

      public int size()
      method to know the size of the list of the DefaultBlockList
      Returns:
      the size of the list
    • contains

      public boolean contains(net.minecraft.block.BlockState state)
      method to know if a BlockState is present
      Parameters:
      state - the state that will be tested
      Returns:
      true if the BlockState is present, false if not
    • getCleaned

      public abstract List<T> getCleaned(List<T> blockList)

      Method to clean a blockList.

      In the case, there are multiple common BlockState.

      All the blockPos common of a BlockState will be fused in a single BlockState

      Parameters:
      blockList - the blockList that will bea cleaned
      Returns:
      the cleaned version of the list
    • sort

      public void sort(BlockSorter sorter)
      Method to sort all the BlockPos List
      Parameters:
      sorter - the sorter that will sort the BlockPos
    • getSorted

      public List<T> getSorted(BlockSorter sorter)
      method to get the list with the blockPos being sorted
      Parameters:
      sorter - the sorter object that will be used to sort the list
      Returns:
      the list of the comparator
    • getOrdered

      public abstract V getOrdered()
      Method to get the ordered version of the comparator
      Returns:
      the ordered version
    • getOrderedSorted

      public V getOrderedSorted(BlockSorter sorter)
      Method to get the ordered version of the comparator as well as being sorted
      Parameters:
      sorter - the sorter that will sort the BlockPos
      Returns:
      the sorted comparator related to this object
    • placeAll

      public void placeAll(net.minecraft.world.StructureWorldAccess worldAccess)
      Method to place all the blocks in the comparator
      Parameters:
      worldAccess - the world where the blocks will be placed
    • placeAllWithVerification

      public void placeAllWithVerification(net.minecraft.world.StructureWorldAccess worldAccess)
      Method to place all the blocks in the comparator with the BlockPos getting verified
      Parameters:
      worldAccess - the world where the blocks will be placed
    • placeAllWithDeletion

      public void placeAllWithDeletion(net.minecraft.world.StructureWorldAccess worldAccess)
      Method to place all the blocks in the comparator and removing the BlockPos
      Parameters:
      worldAccess - the world where the blocks will be placed
    • placeAllWithVerificationDeletion

      public void placeAllWithVerificationDeletion(net.minecraft.world.StructureWorldAccess worldAccess)
      Method to place all the blocks in the comparator with the BlockPos getting verified and the getting deleted
      Parameters:
      worldAccess - the world where the blocks will be placed