[1.12] Performance improvements, bug fixes and clean up
This PR is a collection of a lot of performance improvements, bug fixes and a bit of code clean up. Due to the huge amount of changes I recommend checking every commit individually. This should be doable because every commit only changes a single thing and the individual changes are (currently) not split among multiple commits.
Currently all changes are untested. I will try to do some testing in the next days and report back.
Here is a list of the reasoning behind each commit:
-
Improve LocalWorld#isStructureInRadius implementations Performance: Iterate whole area directly instead of going in circles (usually done to find the nearest structure but that isn't needed here) Bug Fix:
MapGenStructure#canSpawnStructureAtCoordsmay crash due toMapGenBase#worldbeing null Clean up -
Improve EntityNames#toInternalName Performance: Very slow, iterates map + a lot of regex. Not exactly the same functionality as before. Previously it removed all occurances of "minecraft:", "entity" and "_". This means something like
z_ominecraft:mbentityi_e__would be a valid alias forzombie. Now only the "minecraft:" prefix is removed and the aliases specified byEntityNamesare supported. -
Fix captureBlockSnapshots corruption when setBlockState errors Bug Fix: When
Chunk#setBlockStatethrows an exception thecaptureBlockStatesfield might get corrupted which creates a massive memory leak -
Clean up BlockPos2D Clean up
-
Fix missing BlockPos2D#hashCode implementation Bug Fix: This class is used as a
HashMapkey inOTGChunkGeneratorbut is missing ahashCodeimplementation -
Clean up BlockPos3D Clean up
-
Fix BlockPos3D#equals Bug Fix: y coordinate is not compared
-
Fix missing BlockPos3D#hashCode implementation Bug Fix: Didn't find any hash map usage but doesn't hurt to implement this as well
-
Replace FifoMap with LRUCache Performance: Use access order instead of write order to determine which entry to remove (LRU instead of FIFO). Also, initialize map with sufficient size so that no resizing is ever needed,
-
Improve DimensionConfigBase constructor Performance: Avoid creating
ArrayListjust to calltoArrayin the end -
Improve DefaultMaterial lookups Performance: Use
HashMapinstead ofTreeMapforlookupNameClean up -
Improve PlantType lookup Performance: Use
HashMapinstead ofTreeMapforLOOKUP_MAP -
Improve ChunkGenerator#getChunk Performance: Caching like this only hurts performance. Calling
getLoadedChunkis unnecessary if just callinggetChunkwhen the result is null. -
Clean up BiomeGroup Clean up
-
Fix unnecessary ArrayList creation Performance: Iterate list directly instead of creating
ArrayListfrom sub list -
Improve BiomeGroup depth map cache Performance:
BiomeGroupManager#isBiomeDepthMapEmptyonly checks if any depth map is non-empty but this can be done without creating a depth map. -
Remove unnecessary initGroupSeed call Clean up:
LayerLandRandomdoesn't callnextGroupIntwhich makes this useless -
Rename getRandomOf4 to mostCommonOrRandom Clean up: Confusing name
-
Improve mostCommonOrRandom Performance: Less comparisons
-
Add InvalidConfigException constructor with cause argumnet Feature: Adds option to create
InvalidConfigExceptionwith a cause. Stacktrace won't be truncated when throwing aInvalidConfigExceptionusing the new constructor this way. -
Clean up StringHelper Performance: Avoid
Collection#toArrayinjoin. UseInvalidConfigExceptionconstructor with cause. Clean up -
Improve StringHelper.readCommaSeperatedString Performance: Use
ArrayListinstead ofLinkedList. ReturnListinstead of callingList#toArrayat the end. Clean up -
Clean up Resource.hashCode Clean up
-
Improve FileSettingsReaderOTGPlus.readSettings Performance: Only use up to 3 calls to
indexOforlastIndexOfper line. Clean up -
Improve NBT reading Performance: Use
BufferedInputStream -
Fix silver shulker box id Bug Fix: Wrong id (228 is cyan shulker box)
-
Add glazed terracotta Bug Fix: Add missing glazed terracotta entries
-
Remove "UNKNOWN_BLOCK" Bug Fix: IDs not used by vanilla will used by mods
-
Add fastutil dependency Feature: Make FastUtil 7.1.0 available in common package as it is used by Minecraft already
-
Improve layer random number generator Implement custom RNG (similar to
java.util.SplittableRandom) to generate good random numbers.LayerRNGserves as an abstraction layer to support legacy RNG implementation for old worlds. StoreWorldSaveDatainServerConfigProviderto be able to determine the OTG which was used to create a world. ~~NOTE: Currently the new RNG is unused because it expects the world creation version to be>=9but I didn't change the world creation version yet (see here)~~Fixed -
Create WeightedList to replace TreeMap iteration Performance: Implement
WeightedListto avoidTreeMapiteration.WeightedList#getRandomreturns a random element based on the weight by traversing a AVL tree. -
Format LocalMaterialData Clean up
-
Format ReplacedBlocksMatrix Clean up
-
Reimplement LocalMaterialData Reimplementation of
LocalMaterialDataand its subclasses for various performance improvements and bug fixes. The most important changes are: Use enum +Reference2IntMapto greatly speed upMaterialSet#containsMakeLocalMaterialDataimmutable ReplaceLocalMaterialData#canSnowFallOnwithLocalWorld#canPlaceSnowAtto allow correct checking if snow is placeable Avoid allDefaultMaterialmethods because most are just approximations and don't work for modded blocks anyway