Class BlockListComparator<T extends DefaultBlockList,U,V extends OrderedBlockListComparator<W>,W>
java.lang.Object
net.rodofire.easierworldcreator.blockdata.blocklist.basic.comparator.BlockListComparator<T,U,V,W>
- Type Parameters:
T- The type of theBlockListManagerthat will be managed by the comparatorU- The type of theBlockData. This represents everything to describe theBlock. Usually, it would beBlockState. But there are some cases that require more data like NbtCompounds.V- The type of theOrderedBlockListComparator(class to manage BlockList where theBlockPosare ordered no matter theBlockData, contrary to this class where eachBlockPosare organized depending on theBlockData), related to the object so that no data is lost, or no incompatibilities are presentW- The type of theBlockData, like<U>, but for theOrderedBlockListComparator. Copy and paste the object that is required to the relatedOrderedBlockListComparator
- 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.
- Instead of searching for a
BlockStateinside the list, we use theindexMap. - The map allows us to get the place of the related
BlockStatein theposList. - 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
BlockStateare duplicated). - ability to sort each
BlockPosrelated to oneT - convert this
BlockListManagerinto aOrderedBlockListComparatorthat would allow for more flexibility on how are the BlockPos kept - provides some custom getters.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptioninit an empty comparatorBlockListComparator(List<T> blockLists) init a comparatorBlockListComparator(T blockList) init a comparator -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(net.minecraft.block.BlockState state) method to know if aBlockStateis presentget()method to get the listget(int index) method to get aDefaultBlockListbased on the indexgetCleaned(List<T> blockList) Method to clean a blockList.getFirst()method to get the firstDefaultBlockListof the listgetLast()method to get the lastDefaultBlockListof the listabstract VMethod to get the ordered version of the comparatorgetOrderedSorted(BlockSorter sorter) Method to get the ordered version of the comparator as well as being sortedmethod to get a randomDefaultBlockListof the listgetRandom(net.minecraft.util.math.random.Random random) method to get a randomDefaultBlockListof the listgetSorted(BlockSorter sorter) method to get the list with the blockPos being sortedprotected abstract voidmethod tu initialize the indexes.voidplaceAll(net.minecraft.world.StructureWorldAccess worldAccess) Method to place all the blocks in the comparatorvoidplaceAllWithDeletion(net.minecraft.world.StructureWorldAccess worldAccess) Method to place all the blocks in the comparator and removing the BlockPosvoidplaceAllWithVerification(net.minecraft.world.StructureWorldAccess worldAccess) Method to place all the blocks in the comparator with the BlockPos getting verifiedvoidplaceAllWithVerificationDeletion(net.minecraft.world.StructureWorldAccess worldAccess) Method to place all the blocks in the comparator with the BlockPos getting verified and the getting deletedvoidadd a List of BlockListfinal voidmethod to combine a number ofList<T>abstract voidadd a BlockList to the listintsize()method to know the size of the list of theDefaultBlockListvoidsort(BlockSorter sorter) Method to sort all the BlockPos ListtoString()
-
Field Details
-
blockLists
the List of BlockList that are managed -
indexes
Map used for better performance:- Instead of searching for a
BlockStateinside the list, we use theindexMap. - The map allows us to get the place of the related
BlockStatein theposList. - 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 theBlockData. This represents everything to describe theBlock. Usually, it would beBlockState. But there are some cases that require more data like NbtCompounds. - Instead of searching for a
-
-
Constructor Details
-
BlockListComparator
init a comparator- Parameters:
blockLists- the list of blockList that will be indexed
-
BlockListComparator
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
method to combine a number ofList<T>- Parameters:
lists- the list to combine
-
put
add a List of BlockList- Parameters:
blockLists- the list that will be put
-
put
add a BlockList to the list- Parameters:
type- the blockList that will be added
-
get
method to get the list- Returns:
- the list of the comparator
-
get
method to get aDefaultBlockListbased on the index- Parameters:
index- the index that will be used to get the DefaultBlockList- Returns:
- the DefaultBlockList related to the index
-
getFirst
method to get the firstDefaultBlockListof the list- Returns:
- the first
DefaultBlockListof the list
-
getLast
method to get the lastDefaultBlockListof the list- Returns:
- the last
DefaultBlockListof the list
-
getRandom
method to get a randomDefaultBlockListof the list- Returns:
- a random DefaultBlockList of the list
-
getRandom
method to get a randomDefaultBlockListof 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 theDefaultBlockList- Returns:
- the size of the list
-
contains
public boolean contains(net.minecraft.block.BlockState state) method to know if aBlockStateis present- Parameters:
state- the state that will be tested- Returns:
- true if the
BlockStateis present, false if not
-
getCleaned
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
Method to sort all the BlockPos List- Parameters:
sorter- the sorter that will sort the BlockPos
-
getSorted
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
Method to get the ordered version of the comparator- Returns:
- the ordered version
-
getOrderedSorted
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
-
toString
-