Class OrderedBlockListManager

java.lang.Object
fr.rodofire.ewc.blockdata.blocklist.OrderedBlockListManager

public class OrderedBlockListManager extends Object
OrderedBlockListManager class. It allows you to sort the positions no matter the BlockData.

It represents a final state of the BlockListManager, meaning that no modifications can be done after putting BlockData. For example, you cannot change a state related to a blockPos. You cannot get The BlockPos related to a `BlockData`. If you want to do something like this, use a BlockListManager.

While you can combine and put other Ordered / Base BlockListManager, it is not recommended as it has some important performance. You should combine BlockListManager then convert it to ordered.

  • Constructor Details

    • OrderedBlockListManager

      public OrderedBlockListManager(OrderedBlockListManager manager)
      constructor to init a OrderedBlockListManager.
      Parameters:
      manager - the manager to be fused
    • OrderedBlockListManager

      public OrderedBlockListManager(BlockListManager manager)
      constructor to init a OrderedBlockListManager.
      Parameters:
      manager - the manager to be fused
    • OrderedBlockListManager

      public OrderedBlockListManager(net.minecraft.world.level.block.state.BlockState state, List<net.minecraft.core.BlockPos> posList)
      init a default ordered blockList comparator
      Parameters:
      state - the state that will be tested and put (in the case it doesn't exist)
      posList - the blockPos that will be put related to the given state
    • OrderedBlockListManager

      public OrderedBlockListManager(Map<net.minecraft.world.level.block.state.BlockState,List<net.minecraft.core.BlockPos>> info)
      init a comparator
      Parameters:
      info - the map that will be used to init the comparator
    • OrderedBlockListManager

      public OrderedBlockListManager()
      init an empty comparator
  • Method Details

    • arePosEmpty

      public boolean arePosEmpty()
      Method to know if no BlockPos are present in the posMap
      Returns:

      -true if no BlockPos are present in the map.

      -false if at least one BlockPos is present.

    • removeBlockPos

      public long removeBlockPos(int index)
      Removes the BlockPos at the specified index from the posList and posMap.
      Parameters:
      index - the index of the BlockPos to remove.
      Returns:
      the removed BlockPos.
      Throws:
      IndexOutOfBoundsException - if the index is out of range.
    • removeBlockPosPair

      public com.mojang.datafixers.util.Pair<Long,net.minecraft.world.level.block.state.BlockState> removeBlockPosPair(int index)
      Removes the BlockPos at the specified index from the posList and retrieves its associated state.
      Parameters:
      index - the index of the BlockPos to remove.
      Returns:
      a Pair containing the removed BlockPos and its associated state.
      Throws:
      IndexOutOfBoundsException - if the index is out of range.
    • removeFirstPos

      public long removeFirstPos()
      Removes and returns the first BlockPos from the posList and posMap.
      Returns:
      the first BlockPos that was removed.
      Throws:
      IndexOutOfBoundsException - if the list is empty.
    • removeLastPos

      public long removeLastPos()
      Removes and returns the last BlockPos from the posList and posMap.
      Returns:
      the first BlockPos that was removed.
      Throws:
      IndexOutOfBoundsException - if the list is empty.
    • removeFirstBlockPos

      public com.mojang.datafixers.util.Pair<Long,net.minecraft.world.level.block.state.BlockState> removeFirstBlockPos()
      Removes and returns the first BlockPos and its associated state from the posList.
      Returns:
      a Pair containing the first BlockPos and its associated state.
      Throws:
      IndexOutOfBoundsException - if the list is empty.
    • removeLastBlockPosPair

      public com.mojang.datafixers.util.Pair<Long,net.minecraft.world.level.block.state.BlockState> removeLastBlockPosPair()
      Removes and returns the last BlockPos and its associated state from the posList.
      Returns:
      a Pair containing the last BlockPos and its associated state.
      Throws:
      IndexOutOfBoundsException - if the list is empty.
    • clear

      public void clear()
      Clears all elements from posList, posMap, and statesMap. After this operation, all structures will be empty.
    • getPosList

      public List<it.unimi.dsi.fastutil.longs.LongShortImmutablePair> getPosList()
    • getBlockPos

      public long getBlockPos(int index)
      Retrieves the BlockPos at a specified index.
      Parameters:
      index - the index of the BlockPos to retrieve
      Returns:
      the BlockPos at the specified index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • getFirstBlockPos

      public long getFirstBlockPos()
      Retrieves the first BlockPos in the position map.
      Returns:
      the first BlockPos
      Throws:
      NoSuchElementException - if the position map is empty
    • getLastBlockPos

      public long getLastBlockPos()
      Retrieves the last BlockPos in the position map.
      Returns:
      the last BlockPos
      Throws:
      NoSuchElementException - if the position map is empty
    • getRandomBlockPos

      public long getRandomBlockPos()
      Retrieves a random BlockPos from the position map.
      Returns:
      a random BlockPos
      Throws:
      IllegalStateException - if the position map is empty
    • getRandomBlockPos

      public long getRandomBlockPos(net.minecraft.util.RandomSource random)
      Retrieves a random BlockPos from the position map using a provided random generator.
      Parameters:
      random - the Random object to use for generating random indices
      Returns:
      a random BlockPos
      Throws:
      IllegalStateException - if the position map is empty
    • posSize

      public int posSize()
      Retrieves the number of entries in the position map.
      Returns:
      the size of the position map
    • stateSize

      public int stateSize()
      method to get the size of the stateMap
      Returns:
      the size of the state map
    • isPosEmpty

      public boolean isPosEmpty()
      method to know if no blockPos are present
      Returns:
      true is no blockPos are present, false if not
    • isStateEmpty

      public boolean isStateEmpty()
      method to know if no state is present
      Returns:
      true is no blockPos are present, false if not
    • getBlockState

      public net.minecraft.world.level.block.state.BlockState getBlockState(short index)
      method to get the blockState related to the index
      Parameters:
      index - the index of the BlockState
      Returns:
      the blockState related to the index
    • get

      public BlockDataKey get(int index)
    • getCompound

      public net.minecraft.nbt.CompoundTag getCompound(short index)
      method to get the blockState related to the index
      Parameters:
      index - the index of the BlockState
      Returns:
      the blockState related to the index
    • getFirstBlockState

      public net.minecraft.world.level.block.state.BlockState getFirstBlockState()
      Method to get the first BlockState
      Returns:
      the first BlockState
    • getFirst

      public BlockDataKey getFirst()
    • getFirstCompound

      public net.minecraft.nbt.CompoundTag getFirstCompound()
    • getLastBlockState

      public net.minecraft.world.level.block.state.BlockState getLastBlockState()
      Method to get the last BlockState
      Returns:
      the last BlockState
    • getLast

      public BlockDataKey getLast()
    • getLastCompound

      public net.minecraft.nbt.CompoundTag getLastCompound()
    • setPosList

      public void setPosList(List<it.unimi.dsi.fastutil.longs.LongShortImmutablePair> posList)
    • put

      public void put(OrderedBlockListManager comparator)
    • put

      public OrderedBlockListManager put(BlockList blockList)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, net.minecraft.nbt.CompoundTag tag, it.unimi.dsi.fastutil.longs.LongArrayList posList)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, net.minecraft.nbt.CompoundTag tag, long pos)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, net.minecraft.nbt.CompoundTag tag, List<net.minecraft.core.BlockPos> posList)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, net.minecraft.nbt.CompoundTag tag, net.minecraft.core.BlockPos pos)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, it.unimi.dsi.fastutil.longs.LongArrayList pos)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, long pos)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, List<net.minecraft.core.BlockPos> posList)
    • put

      public OrderedBlockListManager put(net.minecraft.world.level.block.state.BlockState state, net.minecraft.core.BlockPos pos)
    • getFromPosIndex

      public BlockDataKey getFromPosIndex(int index)
    • getPlacementRuleFromPosIndex

      public Optional<StructurePlacementRuleManager> getPlacementRuleFromPosIndex(int index)
    • placeLast

      public boolean placeLast(net.minecraft.world.level.WorldGenLevel world)
    • placeFirst

      public boolean placeFirst(net.minecraft.world.level.WorldGenLevel world)
    • placeAll

      public boolean placeAll(net.minecraft.world.level.WorldGenLevel worldAccess)
    • placeLastNDelete

      public boolean placeLastNDelete(net.minecraft.world.level.WorldGenLevel world)
    • placeNDelete

      public boolean placeNDelete(net.minecraft.world.level.WorldGenLevel world, int index)
      for the most performance, it is recommended to not use this method where placeLastNDelete() can be applied
    • placeAllNDelete

      public boolean placeAllNDelete(net.minecraft.world.level.WorldGenLevel worldAccess)
    • place

      public boolean place(net.minecraft.world.level.WorldGenLevel world, int index)
      Method to place a BlockPos based on the index. No placement flag is selected so the default took is Block.UPDATE_KNOWN_SHAPE. No block updates are performed except for the client rendering, allowing for a huge gain in performance.
      Parameters:
      world - the world where the block will be placed
      index - the index of the list of the BlockPos
      Returns:
      • true if it was placed
      • false else
    • place

      public boolean place(net.minecraft.world.level.WorldGenLevel world, int index, int flag)
    • init

      public void init(net.minecraft.world.level.WorldGenLevel world)