Class OrderedBlockListComparator<T>

java.lang.Object
net.rodofire.easierworldcreator.blockdata.blocklist.ordered.comparator.OrderedBlockListComparator<T>
Type Parameters:
T - the object that represents the state of the blocks usually a BlockState, but can include Nbt Compounds depending on the case or Blocks, for example. For example, CompoundOrderedBlockListComparator uses a Pair<BlockState, NbtCompound> to connect Nbt to a BlockState
Direct Known Subclasses:
CompoundOrderedBlockListComparator, DefaultOrderedBlockListComparator

public abstract class OrderedBlockListComparator<T> extends Object

Class to manage ordered BlockList.

For memory saving, we use a link between states and BlockPos.

  • Since that BlockState takes a lot of memory, we use a unique index represented by a short to make the link.
  • We also want the order of the BlockPos, so we can't compact the BlockPos into one BlockState easily and without having important performance losses.
  • Since that it is highly improbable that there are more than 32 000 different T objects, we use the short (instead of int), allowing us to save two Bytes of data per BlocPos.
To create a class based on the comparator, you can follow this simple example:
 public class XOrderedBlockListComparator extends OrderedBlockListComparator<BlockState> {
      //constructor
      //abstracts methods
      //custom methods
 }
 
To know what to put in the <> read that:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected LinkedHashMap<net.minecraft.util.math.BlockPos,Short>
    we're using the short to make the link between the T objects (blockStates in the most cases) and the BlockPos.
    protected final com.google.common.collect.BiMap<Short,T>
    we're using BiMap to be able to get the short from the T objects and the other way around
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor to init an empty OrderedBlockListComparator.
    OrderedBlockListComparator(Map<T,List<net.minecraft.util.math.BlockPos>> info)
    constructor to init a OrderedBlockListComparator.
    OrderedBlockListComparator(T states, List<net.minecraft.util.math.BlockPos> posList)
    constructor to init a OrderedBlockListComparator.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Method to know if no BlockPos are present in the posMap
    net.minecraft.util.math.BlockPos
    getBlockPos(int index)
    Retrieves the BlockPos at a specified index.
    Set<net.minecraft.util.math.BlockPos>
    getBlockPos(List<T> states)
    method to get all the BlockPos related to a list of states
    Set<net.minecraft.util.math.BlockPos>
    getBlockPos(T state)
    Method to gate all the BlockPos related to provided state
    Set<net.minecraft.util.math.BlockPos>
    Retrieves a set of all BlockPos entries in the position map.
    net.minecraft.util.math.BlockPos
    Retrieves the first BlockPos in the position map.
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
    Method to get the first BlockPos pair.
    net.minecraft.util.math.BlockPos
    Retrieves the last BlockPos in the position map.
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
    method to get the last BlockPos pair
    List<net.minecraft.util.math.BlockPos>
     
    LinkedHashMap<net.minecraft.util.math.BlockPos,Short>
    Method to get the posMap related to the object
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
    getPosPair(int index)
     
    net.minecraft.util.math.BlockPos
    Retrieves a random BlockPos from the position map.
    net.minecraft.util.math.BlockPos
    getRandomBlockPos(net.minecraft.util.math.random.Random random)
    Retrieves a random BlockPos from the position map using a provided random generator.
    short
    method to get the index related to the T object.
    protected List<T>
    Retrieves a list of all states in the states map.
    boolean
    method to know if no blockPos are present
    boolean
    isPresent(net.minecraft.util.math.BlockPos pos)
    Method to know if a BlockPos is present in the comparator
    boolean
    isPresent(T state)
    Method to know if an object T is present in the comparator
    boolean
    method to know if no state is present
    abstract void
    place(net.minecraft.world.StructureWorldAccess world, int index)
    method to place the Block related to the index
    abstract void
    placeFirst(net.minecraft.world.StructureWorldAccess world)
    method to place the first Block
    abstract void
    placeFirstWithDeletion(net.minecraft.world.StructureWorldAccess world)
    Method to place the first Block and deleting it.
    abstract boolean
    placeFirstWithVerification(net.minecraft.world.StructureWorldAccess world)
    Method to place the first Block.
    abstract boolean
    placeFirstWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world)
    Method to place the first Block and deleting it.
    abstract void
    placeLast(net.minecraft.world.StructureWorldAccess world)
    Method to place the last Block of the comparator.
    abstract void
    placeLastWithDeletion(net.minecraft.world.StructureWorldAccess world)
    Method to place the last Block of the comparator and removing it then.
    abstract boolean
    placeLastWithVerification(net.minecraft.world.StructureWorldAccess world)
    Method to place the last Block.
    abstract boolean
    placeLastWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world)
    Method to place the last Block of the comparator and removing it then.
    abstract void
    placeWithDeletion(net.minecraft.world.StructureWorldAccess world, int index)
    method to place the block with the deletion of the BlockPos
    abstract boolean
    placeWithVerification(net.minecraft.world.StructureWorldAccess world, int index)
    Method to place the block related to the index.
    abstract boolean
    placeWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world, int index)
    Method to place the block with the deletion of the BlockPos The method also performs verification to know if the block can be placed.
    int
    Retrieves the number of entries in the position map.
    void
    put(T state, List<net.minecraft.util.math.BlockPos> posList)
    Method to add a T object as well as a list of BlockPos.
    void
    put(T state, net.minecraft.util.math.BlockPos pos)
     
    void
    putAll(Map<T,List<net.minecraft.util.math.BlockPos>> info)
    Method to add a T object as well as a list of BlockPos.
    void
     
    net.minecraft.util.math.BlockPos
    removeBlockPos(int index)
     
    void
    removeBlockPos(List<net.minecraft.util.math.BlockPos> posList)
    Removes multiple BlockPos entries from the position map.
    void
    removeBlockPos(net.minecraft.util.math.BlockPos pos)
    Removes a single BlockPos entry from the position map.
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
    removeBlockPosPair(int index)
     
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
     
    net.minecraft.util.math.BlockPos
     
    net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T>
     
    void
    removeState(List<T> states)
    method to remove a list of object from the stateMap
    void
    removeState(T state)
    Method to remove a T object from the stateMap.
    void
    replaceState(T oldState, T newState)
    Replaces an old state with a new state in the states map.
    void
    setPosList(List<net.minecraft.util.math.BlockPos> posList)
     
    void
    setPosMap(LinkedHashMap<net.minecraft.util.math.BlockPos,Short> indexes)
    Method to set the posMap
    int
    method to get the size of the stateMap

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • statesMap

      protected final com.google.common.collect.BiMap<Short,T> statesMap
      we're using BiMap to be able to get the short from the T objects and the other way around
    • posMap

      protected LinkedHashMap<net.minecraft.util.math.BlockPos,Short> posMap
      we're using the short to make the link between the T objects (blockStates in the most cases) and the BlockPos.
  • Constructor Details

    • OrderedBlockListComparator

      public OrderedBlockListComparator(T states, List<net.minecraft.util.math.BlockPos> posList)
      constructor to init a OrderedBlockListComparator.
      Parameters:
      states - the T object that will init the stateMap.
      posList - the BlockPos List related to the states that will init the posMap
    • OrderedBlockListComparator

      public OrderedBlockListComparator(Map<T,List<net.minecraft.util.math.BlockPos>> info)
      constructor to init a OrderedBlockListComparator.
      Parameters:
      info - a map that provides a list of BlockPos and the T objects related to them.

      That will be used to initialize the posMap as well as the stateMap.

    • OrderedBlockListComparator

      public OrderedBlockListComparator()
      Constructor to init an empty OrderedBlockListComparator.
  • Method Details

    • put

      public void put(T state, List<net.minecraft.util.math.BlockPos> posList)
      Method to add a T object as well as a list of BlockPos.

      - In the case there's already a T object, the method will only add the BlockPos list to the posMap with the related index.

      - In the other case, the T object will be added to the stateMap with a new index. And will put the blockPos List in the posMap

      Parameters:
      state - the object that will be compared, added and assigned an index in the case it is not present
      posList - the List of BlockPos that you want to add
    • put

      public void put(T state, net.minecraft.util.math.BlockPos pos)
    • putAll

      public void putAll(Map<T,List<net.minecraft.util.math.BlockPos>> info)
      Method to add a T object as well as a list of BlockPos.

      - In the case there's already a T object, the method will only add the BlockPos list to the posMap with the related index.

      - In the other case, the T object will be added to the stateMap with a new index. And will put the blockPos List in the posMap

      We're calling the put method for all the objects in the map

      Parameters:
      info - a map of T object linked with a List<BLockPos>
    • isPresent

      public boolean isPresent(T state)
      Method to know if an object T is present in the comparator
      Parameters:
      state - the state that will be tested to know if it is present or not
      Returns:

      -true if the state is present.

      -false if not

    • isPresent

      public boolean isPresent(net.minecraft.util.math.BlockPos pos)
      Method to know if a BlockPos is present in the comparator
      Parameters:
      pos - the state that will be tested to know if it is present or not
      Returns:

      -true if the pos is present.

      -false if not

    • 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.

    • getStateIndex

      public short getStateIndex(T state)
      method to get the index related to the T object.
      Parameters:
      state - the state that will be compared
      Returns:
      The index related to the T if it is present.

      - We return -1 in case it is not present.

      Be careful when using this method.

      Always check that the value is not equals to -1

    • removeState

      public void removeState(List<T> states)
      method to remove a list of object from the stateMap
      Parameters:
      states - the objects that will be removed
    • removeState

      public void removeState(T state)

      Method to remove a T object from the stateMap.

      Removing that object will also remove every BlockPos related to that object

      Parameters:
      state - the object that will be removed form the stateMap
    • replaceState

      public void replaceState(T oldState, T newState)
      Replaces an old state with a new state in the states map.
      Parameters:
      oldState - the state to be replaced
      newState - the state to replace with
    • removeBlockPos

      public void removeBlockPos(List<net.minecraft.util.math.BlockPos> posList)
      Removes multiple BlockPos entries from the position map.
      Parameters:
      posList - the list of BlockPos objects to be removed
      Throws:
      NullPointerException - if posList or any BlockPos in it is null
    • removeBlockPos

      public void removeBlockPos(net.minecraft.util.math.BlockPos pos)
      Removes a single BlockPos entry from the position map.
      Parameters:
      pos - the BlockPos to be removed
      Throws:
      NullPointerException - if pos is null
    • removeBlockPos

      public net.minecraft.util.math.BlockPos removeBlockPos(int index)
    • removeBlockPosPair

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> removeBlockPosPair(int index)
    • removeFirstPos

      public net.minecraft.util.math.BlockPos removeFirstPos()
    • removeFirstBlockPos

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> removeFirstBlockPos()
    • removeLastBlockPosPair

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> removeLastBlockPosPair()
    • removeAll

      public void removeAll()
    • getT

      protected List<T> getT()
      Retrieves a list of all states in the states map.
      Returns:
      a list of all states
    • getPosMap

      public LinkedHashMap<net.minecraft.util.math.BlockPos,Short> getPosMap()
      Method to get the posMap related to the object
      Returns:
      the indexes (a Map of BlockPos and indexes)
    • setPosMap

      public void setPosMap(LinkedHashMap<net.minecraft.util.math.BlockPos,Short> indexes)
      Method to set the posMap
      Parameters:
      indexes - the posMap that will be set (a Map of BlockPos and indexes)
    • setPosList

      public void setPosList(List<net.minecraft.util.math.BlockPos> posList)
    • getPosList

      public List<net.minecraft.util.math.BlockPos> getPosList()
    • getBlockPos

      public Set<net.minecraft.util.math.BlockPos> getBlockPos(T state)
      Method to gate all the BlockPos related to provided state
      Parameters:
      state - the parameter that will be used to get the related BlockPos
      Returns:
      a Set of BlockPos that correspond to the provided state.
    • getBlockPos

      public Set<net.minecraft.util.math.BlockPos> getBlockPos(List<T> states)
      method to get all the BlockPos related to a list of states
      Parameters:
      states - the states that will be used to get all the related blockPos
      Returns:
      a set of BlockPos that are linked to the provided states.
    • getBlockPosSet

      public Set<net.minecraft.util.math.BlockPos> getBlockPosSet()
      Retrieves a set of all BlockPos entries in the position map.
      Returns:
      a set of all BlockPos objects
    • getBlockPos

      public net.minecraft.util.math.BlockPos 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 net.minecraft.util.math.BlockPos getFirstBlockPos()
      Retrieves the first BlockPos in the position map.
      Returns:
      the first BlockPos
      Throws:
      NoSuchElementException - if the position map is empty
    • getLastBlockPos

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

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

      public net.minecraft.util.math.BlockPos getRandomBlockPos(net.minecraft.util.math.random.Random 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
    • getPosPair

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> getPosPair(int index)
    • getFirstPosPair

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> getFirstPosPair()
      Method to get the first BlockPos pair.
      Returns:
      the pair of BlockPos and BlockState/nbt
    • getLastPosPair

      public net.minecraft.util.Pair<net.minecraft.util.math.BlockPos,T> getLastPosPair()
      method to get the last BlockPos pair
      Returns:
      the pair of BlockPos and BlockState/nbt
    • 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
    • place

      public abstract void place(net.minecraft.world.StructureWorldAccess world, int index)
      method to place the Block related to the index
      Parameters:
      world - the world the block will be placed
      index - the index of the BlockPos
    • placeWithDeletion

      public abstract void placeWithDeletion(net.minecraft.world.StructureWorldAccess world, int index)
      method to place the block with the deletion of the BlockPos
      Parameters:
      world - the world the block will be placed
      index - the index of the block
    • placeWithVerification

      public abstract boolean placeWithVerification(net.minecraft.world.StructureWorldAccess world, int index)
      Method to place the block related to the index. The method also performs verification to know if the block can be placed.
      Parameters:
      world - the world the block will be placed
      index - the index of the block
      Returns:
      true if the block was placed, false if not
    • placeWithVerificationDeletion

      public abstract boolean placeWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world, int index)
      Method to place the block with the deletion of the BlockPos The method also performs verification to know if the block can be placed.
      Parameters:
      world - the world the block will be placed
      index - the index of the block
      Returns:
      true if the block was placed, false if not
    • placeFirst

      public abstract void placeFirst(net.minecraft.world.StructureWorldAccess world)
      method to place the first Block
      Parameters:
      world - the world the block will be placed
    • placeFirstWithDeletion

      public abstract void placeFirstWithDeletion(net.minecraft.world.StructureWorldAccess world)
      Method to place the first Block and deleting it. You shouldn't use this method in normal case since that the method is pretty costly O(n). Use instead placeLastWithDeletion() that is faster O(1).
      Parameters:
      world - the world where the block will be placed
    • placeFirstWithVerification

      public abstract boolean placeFirstWithVerification(net.minecraft.world.StructureWorldAccess world)
      Method to place the first Block.

      The method also performs verification to know if the block can be placed.

      Parameters:
      world - the world where the block will be placed
      Returns:
      true if the block was placed, false if not.
    • placeFirstWithVerificationDeletion

      public abstract boolean placeFirstWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world)

      Method to place the first Block and deleting it.

      The method also performs verification to know if the block can be placed.

      You shouldn't use this method in normal case since that the method is pretty costly O(n).

      Use instead placeLastWithDeletion() that is faster O(1).

      Parameters:
      world - the world where the block will be placed
      Returns:
      true if the block was placed, false if not.
    • placeLastWithDeletion

      public abstract void placeLastWithDeletion(net.minecraft.world.StructureWorldAccess world)
      Method to place the last Block of the comparator and removing it then. Consider using this method because it gives you better performance.
      Parameters:
      world - the world the last block will be placed
    • placeLast

      public abstract void placeLast(net.minecraft.world.StructureWorldAccess world)
      Method to place the last Block of the comparator.
      Parameters:
      world - the world the last block will be placed
    • placeLastWithVerification

      public abstract boolean placeLastWithVerification(net.minecraft.world.StructureWorldAccess world)
      Method to place the last Block.
      Parameters:
      world - the world the last block will be placed The method also performs verification to know if the block can be placed.
      Returns:
      true if the block was placed, false if not
    • placeLastWithVerificationDeletion

      public abstract boolean placeLastWithVerificationDeletion(net.minecraft.world.StructureWorldAccess world)
      Method to place the last Block of the comparator and removing it then. The method also performs verification to know if the block can be placed. Consider using this method because it gives you better performance.
      Parameters:
      world - the world the last block will be placed
      Returns:
      true if the block was placed, false if not